1. Create a winform project.
2. Add a Linq to SQL class named Northwind
3. Open the server resource manager and drag the table to the linq to SQL class. The entity class is generated by.
4. instantiate the DataContext class
NorthwindDataContext dc = new NorthwindDataContext();
5. Now you can use Linq to SQL.
A. query all Employees data
Var ee =
From employee in dc. Employees
Select employee;
B. Add a Where condition to query all cities = London in the Employee table.
e2 = employee employee.City == employee;
C. query the data of EmployeeID <5
e3 = employee employee.EmployeeID < employee;
D. query the employees whose employment date is before January 1, January 1, 1993.
e4 = employee employee.HireDate < DateTime(, , employee;
E. Multiple query Conditions
e5 = employee employee.HireDate < DateTime(, , employee.EmployeeID < employee;
F. like statement
e6 = employee SqlMethods.Like(employee.FirstName, employee;
G. query the specified Column
e7 = employee ===
H. subquery
e8 = employee employee.Orders.Count > employee;
I. Internal Connection
e9 = cus cus.City == ord;
J. Add
Employees m = = = =
K. Modify
e10 = dc.Employees.FirstOrDefault(employee => employee.LastName == =
L. Delete
e10 = dc.Employees.FirstOrDefault(employee => employee.LastName ==
The exercise code uses Vs2012 and the Microsoft northwnd sample database.
Code download: http://pan.baidu.com/s/1pJyh0Mn