Register Login

 

Welcome to the Coach Factor blog. Here you will find all of our ideas on software development. Subscribe at  http://blog.nventive.net.

# Monday, April 21, 2008

nVentive was present in Quebec city at HEROES happen {here}, Microsoft's launch for Visual Studio.Net 2008, SQL Server 2008 and Windows Server 2008.

François and I were experts there on the developer side of things, and the one thing we got asked the most, were questions on LINQ.

Everybody knows that LINQ is the hot new way to query objects in C# using a syntax similar to SQL. It depends on 2 tricks, Extension Methods and Lanbda Expressions.

This is a small sample.

public class Blog

{

   public string Title { get; set; }

}

class Program

{

   static void Main(string[] args)

   {

      IList<Blog> blogs = new List<Blog>();

      blogs.Add(new Blog { Title = "3 cheese lasagna" });

      blogs.Add(new Blog { Title = "Blue cheese alfredo sauce" });

      blogs.Add(new Blog { Title = "Macaroni and cheese" });

      blogs.Add(new Blog { Title = "Angel cake" });

 

      var blogsWithCheese = from blog in blogs

            where blog.Title.ToLower().Contains("cheese")

            select blog;

      //blogsWithCheese contains 3 elements.

   }

}

You can query something that is IEnumerable with LINQ to Objects, or a database itself using LINQ to SQL. If XML is your thing, there is a LINQ to XML variant and let's not forget that there is adapter to query Ado.Net DataSets. If you've heard of Entity Framework, LINQ will also work there to abstract it's object SQL language.

Now there's still more, if you have a source that you'd like to query with LINQ, it's just a matter of implementing IQueryProvider and IQueryable.

There are 2 tools I recommend you use in your adventures with LINQ:

  1. LINQPad is a interactive LINQ learning tool. Check it out, you'll never go back into Query Analyzer after that.
  2. Visual LINQ Query Builder is a plugin for Visual Studio 2008 that will help you develop your queries with a designer, now that's practical.

Monday, April 21, 2008 8:33:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
.net | Announcement
Comments are closed.
Search
Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Statistics
Total Posts: 47
This Year: 0
This Month: 0
This Week: 0
Comments: 2
Sign In