2007.7.20 Li Jianzhong
Introduction to LINQ to SQL
Object-Oriented Domain:
All objects (fields, methods, references ...)
Relational Database:
Everything is centered on table data (rows, columns, and relationships)
Linq to SQL integrates SQL schema information into CLR metadata, and naturally converts objects in the object-oriented field to table data in relational databases, this allows us to use LINQ to easily access relational databases.
As an important component of ADO. NET.
Object Class ing
Note that the [Table] feature corresponds to the Table named "Category" in the database. The [Column] feature corresponds to the columns in the database. If the attribute or field is not marked, the database will not ignore this attribute or field.
DataContext data context object
Note that DataContext is very similar to a database link object, but it provides more support for Linq to SQL.
Query by using Linq to SQL
When the Form is loaded, all category information is displayed.
MSPetShop is a strong-type DataContext. We recommend that you use a strong-type DataContext for Linq to SQL.
We can directly call. Categorys for Strongly typed DataContext to make it easier to use.
In this way, the queried c is a strongly typed object, because it is already the result of the ing from the database to the object.
In the past, this method was not an object method, but a combination of row and column information. In addition, the Select statement needs to be checked in the database server. Now, any syntax errors will be directly checked by the C # compiler, which ensures that most of the careless syntax errors are parsed.
Define basic relationships
Note that Products maps the one-to-multiple relationship between Category and Product. CategoryId is the primary key for the Category table and a foreign key for the Product table.
Note that Category maps the one-to-multiple relationship between Product and Category.
Linq to SQL relational Programming
EntitySet is a set relation and EntityRef is a reference relation.
This is an association query for two tables. First, check a specific column in Category, and then find whether a item in the Product list in this column is selected and select this Product.
Change Data Source
Note that SubmitChanges () has changed the Object layer to the data layer.
Change the data source using Linq to SQL
2010.11.12