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.
Namoskar!!!
Comments
Anonymous
December 18, 2007
The comment has been removedAnonymous
December 19, 2007
If you do a delete, then maybe an insert and an update in the same context and call the SubmitChanges() at the end, are these seperate SQL calls, or is it one trip to the Database?Anonymous
December 19, 2007
The comment has been removedAnonymous
December 20, 2007
The L2S layer translation are variable for different SQL Servers? (Oracle, MS SQL, Postgre, MySQL....etc.) Or it has a default behavior for one database type, and one for each the others.Anonymous
December 21, 2007
L2S works only for Microsoft SQL Server databaseAnonymous
January 08, 2008
You made a small mistake in that L2S returns results as an IQueryable<T> and not an IEnumerable<T>. -krishAnonymous
January 11, 2008
Krish, It also returns IEnumerable<T>, any LINQ returns IEnumerable<T>. Below is a small code snippent which executes, NWDataContext db = new NWDataContext(); IEnumerable<Customer> query = from c in db.Customers select c; IQueryable<Customer> query = from c in db.Customers select c; So both of them works:) WrijuAnonymous
January 18, 2008
There's a Provider for MySQL, Postgre and Oracle on the code2code.net/DB_Linq website. (anyone tried it yet?) This might be the solution to cpatain.crashs question.