Adatis

Adatis BI Blogs

LINQ and SQL Server

Some time ago I reported on LINQ whilst Visual Studio 2008 was still in BETA. On Monday, Nov. 19 2007, Microsoft announced that Visual Studio 2008 and the .NET Framework 3.5 was released to manufacturing (RTM).  Since then I am sure many of you have had many hours playing with VS 2008, WPF, Expression Blend, and all that these new products contain.  Having finally got my hands on it, and found the time, LINQ was the first stop.  So we have a database that we need to run complex queries on where stored procedures just would not be flexible enough.  Further to this Inline SQL is an obvious No No, so perfect scenario for a LINQ to SQL implementation.  Deciding that a DBML (Database Markup Language) structure would work best, generating this file, and getting this file to be update-able was crucial.  So after some research we found a small, unknown command line application called SQLMetal.  This allows you to drop and re-create DBML files, based entirely on a given database.   SqlMetal will always produce a consistent data access layer: SQLMetal is a command line tool that can generate the data access layer in seconds. SqlMetal will produce either C# or VB.Net code. SqlMetal generates a strongly typed data access layer. This is great for reducing runtime error. Now those runtime errors pop up in the development cycle as compile errors, reducing stress on the QA dept, Support dept and upper management, later in the life cycle. SqlMetal can generate strongly typed interfaces for stored procedures and user-defined functions. From the developer point of view, it is now a complete breeze to call either a stored proc and/or a user-defined function. To generate source code from SQL database directly, execute the following: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin> SqlMetal /server:baker   /database:AdventureWorks  /namespace:AdventureWorks  /dbml:AdventureWorks.dbml This creates a DBML file that can be added to your project:    This now gives an entire database structure accessible via LINQ, one thing to be aware of though; ensure you have a solid database design, as SQLMetal will transform you Database design identifying all keys and relationships. And once you have the database as an object model, you can use LINQ as you wish. LINQ to SQL uses ADO.NET under the covers but offer several additional benefits: Reduces complexity Fewer lines of code Strong Typing

LINQ

The LINQ Project is fast becoming one of the most anticipated integrated technologies in Visual Studio 2008 (ORCAS).  LINQ is simply a set of extensions to the .NET framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities. Microsoft have seen that the next big challenge in programming technology is to reduce the complexity of accessing and integrating information that is not natively defined using OO technology. The two most common sources of non-OO information are relational databases and XML. Put simply, the new extensions, allow you to easily perform database type queries directly in code! Standard query operators allow queries to be applied to any IEnumerable<T> based information source.  Here are some sample snippets, taken straight from Microsoft's web site...   using System;using System.Linq;using System.Collections.Generic; class app {static void Main() {  string[] names = { "Burke", "Connor", "Frank",  "Everett", "Albert", "George",  "Harris", "David" };     IEnumerable<string> query = from s in names     where s.Length == 5    orderby s    select s.ToUpper();    foreach (string item in query)  Console.WriteLine(item); }} As you can see in this very simple snippet of code, the idea is to mimic syntax of T-SQL, and if it is as good as it looks so far we may have a lot more to say on it.... I'm sure there will be more to come!

ORCAS CTP..... What's in it?

  The March CTP release of ORCAS (Visual Studio 2008) incorporates a number of new and exciting technologies, as well as enhancing some of the older greats.   The current release of the IDE implements tools and functionality supporting LINQ (Microsoft's .NET Extensions, Language Integration Query), AJAX, Windows Presentation Foundation (codenamed CIDER), Windows Communication Foundation, Windows Workflow Foundation and the .NET framework 3.5 (downloaded separately).  According to Microsoft the latest framework will support applications built in .NET 2.0 and 3.0.  Further to this raft of newly integrated features, it also extends role-based and Team System collaboration features. Traditionally, Microsoft offers a Go Live license at beta 2, and that will almost certainly be the case here. Microsoft have saturated the market with new capabilities, and many of these platforms and technologies represent the culmination of years of work. More on LINQ and ORCAS in coming posts...

Visual Studio 2008 and Javascript Intellisense

Visual Studio 2008 (Codname ORCA) has intorduced a new feature to aid with Web development, official release date has not yet been announced, however a BETA 2 is due to released later this year.  One of the most publicied, and simplistic enhancement to the Visual Studio 2008 enviroment is the somple introduction of intellisensce with Javascript.  You can read more about this here and here.