LINQ to SQL and Entity Framework Operations
One: LINQ to DB framework
1. LINQ to SQL
2. LINQ to ADO Entity Framework
LINQ to SQL is a team
EF is a team ...
LINQ to SQL = EF team.
LINQ to SQL is suitable for some small projects and SQL Server
EF is suitable for medium-form projects and can support Sqllite,mysql,sqlserver
Shopkeeper's project development: the use of the Pure and simple ADO SQL, the project is bigger, we need to divide the table, this time EF bad processing.
Two: LINQ to SQL framework
1. VS Designer gives us automatically generated code to access the database
2. Features: Our context class is inherited from DataContext
<1> in fact, all database operations are DataContext this class to complete.
<2> LINQ to SQL requires that the fields of the entity and table be attribute by one by one.
<3> It's operation is table<t>
public class Program
{
static void Main (string[] args)
{
Datamipdataclassdatacontext context = new Datamipdataclassdatacontext ();
Context. Product.insertonsubmit (New Product ()
//{
ProductID = 7,
ProductName = "Item 7"
//});
Context. SubmitChanges ();
Correlation table Query
var query = from p in context. Product
Join O in context. Order
On P.productid equals O.productid
Select New {ProductID = P.productid, ordertitle = O.ordertitle};
var list = query. ToList ();
}
}
Three: EF
1. It is a class that inherits from the DbContext, so this encapsulates the operation of the database.
2. The operation of the table is the Dbset<t> class
3. We found that EF is still smarter, and if my LINQ statement is a two-table association, and you can see it in the profile, it actually uses only a single table query.
LINQ to SQL and Entity Framework Operations