This is a bit of scattered knowledge about LINQ to SQL. If you want to systematically learn about the knowledge of LINQ to SQL, please refer to scottgu's blog
Part 1: Introduction to LINQ to SQL
Part 2: defining our data model classes
Part 3: querying our database
Part 4: updating our database
Part 5: Binding UI using the ASP: linqdatasource Control
Part 6: retrieving data using Stored Procedures
Part 7: updating our database using Stored Procedures
......
the default curd behavior of LINQ to SQL is a LINQ expression, such as obtaining data.
northwinddatacontext northwind = new northwinddatacontext ();
var Product = from P in northwind. products
where p. categoryid = 1
select P;
the LINQ expression dynamically generates an SQL statement at runtime.
LINQ to SQL also supports stored procedures and custom SQL.
1. sp
drag a written stored procedure to the right of the design panel, in this way, we can use the northwinddatacontext instance to call the stored procedure and convert it into an instance method. This is too simple.
the returned value of a stored procedure is a new data type automatically generated. The naming rule is stored procedure name + result, when you drag SP to the left of the designer to specify the data type, the return value of the method generated by SP is a set of this type. The returned result set also supports the modification and deletion operations of LINQ to SQL.
SP support for insert, update, and delete operations
2. Custom SQL
the built-in executequery of northwinddatacontext provides support for custom SQL queries, you can write and query SQL statements like above, or return custom objects.
the returned result set is also applicable to the modification and deletion operations on objects by using LINQ to SQL.
for the modified and deleted custom SQL statements, execute with executecommand
objects are updated, deleted, and rule verification are also supported, regardless of the LINQ to SQL expression, SP, or custom SQL.