LINQ to SQL
1. Basics of Linq
1.1 Lamada Expession
Allow the definition of anonymous methods using more concise syntax.
Delegate int del (int I );
Del myDelegate = x => x * x;
Int j = myDelegate (5); // j = 25
Public int myDelegateMethod (int I)
{
Return I * I;
}
Del myDelegateUsing = new del (myDelegateMethod );
Int j = myDelegateUsing (5) // j = 25
Func <Northwinds, IQueryable <Orders>, int> q =
CompiledQuery. Compile <Northwinds, int, IQueryable <Orders> (Northwinds nw, int orderid) =>
From o in nw. Orders
Where o. OrderId = orderid
Select o );
Northwinds nw = new Northwinds (conn );
Foreach (Orders o in q (nw, orderid ))
{...}
1.2 Anonymous Types
An object initializer can also be used without specifying the class that will be created with the new operator. Doing that, a new class-An anonymous type-is created.
Customer C1 = new customer {name = "Marco "};
VaR C2 = new customer {name = "Paolo "};
VaR C3 = new {name = "Tom", age = 31 };
VaR C4 = new {c2.name, c2.age };
VaR C5 = new {c1.name, c1.country };
VaR C6 = new {c1.country, c1.name };
1.3 Object and Collection Initializers
// Use object initialization expressions
Customer customer = new customer {name = "Marco", Country = "Italy "};
VaR customers = new [] {
New {name = "Marco", discount = 4.5 },
New {name = "Paolo", discount = 3.0 },
New {name = "Tom", discount = 3.5}
};
1.4 implicative Local Variable Type
Var x = 2.3; // double
Var s = "sample"; // string
1.5 Extend Method
1.6 Auto property
1.7 Query syntax
2 Linq advanced
2.1 IEnumerable
2.2 IEnumerator
2.3 IQueryable
2.4 IQueryProvider
2.5 Expression Tree
3. Linq To SQL
3.1 What is Linq to SQL
LINQ to SQL is an O/RM (object relational mapping) implementationand which allows you to model a relational database using. NET classes. you can then query the database using LINQ, as well as update/insert/delete data from it.
3.2 Modeling Databases
Use a LINQ to SQL designer that provides an easy way to model and visualize a database as a LINQ to SQL object model.
3.3 Extensibility Partial Class and Method
3.4 Query Update Delete Insert Paging
Paging with Skip () & Take () Operators
Varq = query. skip (pagesize * pagenum). take (pagesize)
3.4.1 Query
3.4.2 Upate Delete Insert
3.4.3 Paging
3.5 Use StoreProcedure & User Defined Function
3.6 aspLinqDatasource others UI Controls
3.7 Executing Custom SQL Expressions & DynamicQuery
Custom SQL Expression
DynamicQuery
3.8 Concurrent Conflict
3.9 using dbcontext
3.10 inheritance & Relationship
3.11 some feature: dataloadoptions & caching & lazy loading & datacontext isolation