Wriju's BLOG

.NET, Cloud and everything

LINQ to SQL : Execution Architecture

In L2S query execution can be separated in two major areas. One is to fetching the data another is manipulating the data (update, delete and insert). I use one slide during my L2S demo and here it is,




Fetching data from database


LINQ is only from fetching the data from database. LINQ does not have any query operator for delete, update or insert. When you send LINQ to your L2S layer then L2S translates that to SQL understandable query (T-SQL). This is obvious because as per one of the major design specifications we have decided to make the LINQ independent of any existing API. T-SQL is standard and works for any version of SQL Server database and will continue to work with upcoming releases. Now as usual SQL executes that query and gives the result back to our L2S layer. Then L2S gives us the result back to us in form of IEnumerable<T>.





Manipulating data


When it comes to data manipulation you can go for DML statements or Stored Procedure. If you have Stored Proc then dbml designer allows us to modify the update, delete and insert accordingly. This manipulation happens purely through object model.


For insert

You create an object and add the necessary properties. Then add to the existing collection. Once done call SubmitChanges() method.


For delete

You get the object(s) and using the method Remove(), remove it from the existing collection. Then call SubmitChanges() method.


For update

You get the object(s) to modify. Then call SubmitChanges() method.