LINQ to SQL and Entity Framework Operations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.