LINQ To SQL is an object-relational mapping (ORM) framework that allows the direct 1-1 mapping of a Microsoft SQL Server database tables to .NET classes, and query of the resulting objects using LINQ. LINQ to SQL has been developed to target a rapid development scenario against Microsoft SQL Server where the mapping between the SQL schema and classes in the application is a direct 1-1 mapping, meaning that a table or view being accessed from the database maps to a single class in the application, and a column being accessed maps to a property on the associated class.
Elegible scenarios for using LINQ To SQL is when building applications with a rapid development cycle and a simple one-to-one object to relational mapping against the Microsoft SQL Server family of databases.
When to use it:
- When building an application whose object model is structured very similarly to the existing database structure;
- When a database for the application does not yet exist and there is no predisposition against creating a database schema that mirrors the object model;
- Map a subset of tables directly to classes, with the required columns from each table represented as properties on the corresponding class.
How to use it
- Tutorial 1: Defining Data Model classes
- Tutorial 2: Connecting to database and submitting changes: the DataContext class
- Tutorial 3: Configuring mapping between database table(s) and Data Model class(es) using DataAnnotation (Attributes)
- Tutorial 4: Configuring mapping between database table(s) and Data Model class(es) using an external XML file
- Tutorial 5: Configuring Entity relationships
- Tutorial 6: Updating the database
- Tutorial 7: Querying
- Tutorial 8: Using Stored Procedures
- Tutorial 9: Defining Data Model Classes (Model Inheritance)
- Tutorial 10: Add custom business logic
- Tutorial 11: Creating a new Linq To SQL component
In order to use SQL Server functions (e.g. DATEDIFF, LIKE), these can be used on Linq queries by using the System.Data.Linq.SqlClient.SQLMethods class.
The methods in the SQLMethods class are only supported in LINQ to SQL queries.