Is LINQ to SQL Being Replaced Already?

The short answer is "kind of"; the push is for the ADO.NET Entity Framework to be the encouraged ORM approach from now on.  For the long-winded, thorough explanation of this answer (based on blog posts from Microsoft employees and managers), see the following blog post that someone pointed me toward:

http://www.infoq.com/news/2008/11/DLINQ-Future

Comments

Anonymous
No it isn't, that is a missunderstanding. Linq to sql for SQL Server will always be there just like there are ado.net classes for SQL Server directly tied into the .NET framework libraries.

C# 4.0: Covariance and Contravariance

Someone just sent me a link to a blog post talking about one of the new features of C# 4.0 that will be included with Visual Studio 2010.  It is regarding covariance and contravariance support within the C# language.  This support has been included since C# 2.0 (and consequently, .NET 2.0).  However, it is currently flawed for delegates and interfaces using generics.  Follow this link to find out more about the proposed improvements for the future version of C#:

http://blogs.msdn.com/charlie/archive/2008/10/28/linq-farm-covariance-and-contravariance-in-visual-studio-2010.aspx

Lazy Loading With LINQ

Comments

I’ve been following Rob Conery’s ASP.NET MVC Storefront project that he has been broadcasting to the world via webcasts.  This project has been going on for over 6 months now and there are currently over 20 videos to watch if you really want to get up fully up to speed (which will literally take days).

Anyway, it’s a Storefront website application built on technologies such as Windows Workflow, ASP.NET MVC, CardSpace, StructureMap, PayPal Standard, OpenID, and many others.  While slowly connecting all of these technologies together, Rob attempts to really learn TDD at the same time.  He’s an employee of Microsoft.

One of the things that I really like that he did was to modify the Repository Pattern slightly by adding in Pipes and Filters Pattern on top of it using the IQueryable<> generic in LINQ.  It really is brilliant in my opinion, and if you want to get totally up to speed with just this small part of his project, watch the first 3-5 videos of Rob’s Storefront project.  Then read a blog post by him about an issue he ran into and how he fixed it; the link to his post is at the bottom of this blog entry.

In the process of making this new Repository pattern, he came across some issues with trying to do true Lazy Loading of an object’s relationships to other objects within his LINQ queries.  Basically he wanted to harness the power of IQueryable used by LINQ queries to create the expression that queries against the database but not execute it unless needed.  For instance, if you’ve got a Product object in your model and it contains a collection of UserRating objects, there will be times when you want to retrieve a Product with its UserRatings and times when you only need the Product.  The most efficient way to do it (and coolest) would be to retrieve the object and its relationships the same way every time and let the IQueryable magic of LINQ know when to execute the query against the database and when to leave it as an unexecuted expression.

So Rob created the LazyList object that holds the IQueryable expression until you need to iterate over it or retrieve one of its elements, where it executes the query and fetches real data from the data source.  Rob ran into some unexpected issues with the relationships not loading lazily but was able to solve the problem by using the keyword let in LINQ.  Read his full post about the issues and fixes (and get the source code for the LazyList class) at the following link:

http://blog.wekeroad.com/blog/lazy-loading-with-the-lazylist/

Comments

David
Hi Mike,

I really enjoyed Rob's series too. I've been out of data-centric apps for a little while so I haven't really had a chance to play around with these ideas.

One thing I have been following with interest is the DDD approach to this. I'd really recommend having a read of some of Udi Dahan's posts, as well as Greg Young's recent appearance on Herding Code. This stuff has really challenged my previous ideas on how operations like "loading a Product" should be approached.

LINQ, Lambda Expressions, and IQueryables

Comments

A while back, I went on a research binge about LINQ and Lambda Expressions in C# 3.0.  In my research I also learned about the amazing IQueryable<> generic.  I was just recently reminded of this knowledge surge and figured it could probably benefit many people.

So here are some links I think you just might find as interesting as I do: