Thursday, January 15, 2009

Optimizing Linq to SQL

Lazy Loading in LINQ: LoadWith And AssociateWith DataLoadOptions - Part 1 - LoadWith - Hilton Giesenow's Jumbled Mind

Above is the link to one of the articles I would recommend if you are using Linq to SQL and are now in a situation to tailor solutions to specific problems and/or optimize the performance of your code that is using Linq to SQL for data manipulation purposes.

One thing that we are going to use in the next project, that is different to default Linq setting, is usage of Stored Procedures with Linq entities.
We are creating partial classes for Linq entities and put the static functions in there that call the stored procedures to return sets of those entities. So, we are mapping result sets from stored procedures to entities. I want to try to get a single result from a call to an SP and map it to multiple entities and see how it works.
Next thing is that we are inheriting the original data context and add the function calls there to provide access to the SPs and return the desired data type instead of automatically generated one.

In the article above there are a few tips to have in mind when playing with Linq. DeferredLoadingEnabled and DataLoadOptions, that provides LoadWith and AssociateWith, are a few interesting points. In the given example, Linq is using a JOIN in SQL statement to fetch the resultset containing multiple entities. Sweet.

No comments: