LINQ to SQL and Entity Framework, linqentity
Both LINQ to SQL and Entity Framework are object-link ing technologies that contain the LINQ function.
So why is there the emergence of this thing like LINQ.
To put it simply, LINQ is designed to meet the needs of programmers who do not know how to operate databases. It allows them to think about and persist their data in a data-oriented way.
Essential differences between LINQ to SQL (L2S) and Entity Framework
EF implements better decoupling between the database architecture and the type of our query. With EF, the query object is no longer a class C # That fully corresponds to the database architecture, but a high-level abstraction: Entity Data Model. This provides us with additional flexibility, but it also suffers a loss in terms of performance and simplicity.
Advantages:
As a lightweight ORM framework, LINQ to SQL provides quick application development for Microsoft SQL Server databases. Its advantages include ease of use, simplicity, and high performance.
Entity Framework provides better flexibility for creating mappings between database architectures and Entity classes. It also supports third-party databases other than SQL Server by providing programs.
One of the most popular improvements in EF 4.0 is that it now supports almost the same query function as that of LINQ to SQL. This means that the LINQ-to-db query in the series can be applied to both EF 4.0 and L2S. Moreover, this makes L2S an ideal technology for us to learn how to query databases using LINQ, because it maintains the simplicity of object relationships, and the query principles and technologies we learned are also applicable to EF.
Note :. in NET 3.5, we recommend that you use LINQ, which fully supports mature LINQ. If you use EF, we recommend that you use it. NET 4.0 (VS2010) and later versions, which have mature and complete EF
|
LINQ to SQL |
Entity Framework |
Complexity |
Relatively not complex |
Relatively complex |
Model |
Domain model) |
Conceptual data model) |
Database Server |
SQL Server |
Multiple database products |
Development Time |
Rapid Application Development |
It takes a long time, but more features are supported |
Inheritance |
Difficult |
Easy |
File Type |
DBML File |
EDMX, CDSL, MSL, and SSDL files |
Support for complex types |
Not Supported |
Supported |
Query capability |
Use DataContext |
ESQL, object service, Entity Client |
Performance |
Slow first query |
The first query is slow, but the overall optimization is as follows: |
Complete |
No new version |
New Version |
Generate database from Model |
Supported |
Not Supported |
Complexity:
The more features it supports, the more complicated it will be. Only a few features are supported by LINQ to SQL, so it is relatively complex. EntityFramework supports many features, so it is relatively complicated.
Model:
A one-to-one ing between a data table and a class is provided for the LINQ to SQL statement. If you have Customers, Orders, and Lineitems tables, you will have the Customer, Order, and Lineitem classes to match each table. EntityFramework allows you to have a Customer class, which can match multiple tables. This means that the company name can be in one table, but the address is in another table, and the phone number is in another table.
Database Server:
Only Microsoft SQL Server 2000 and later versions are supported, but even SQLServer2000 has many restrictions. EntityFramework supports IBMDB2, Sybase SqlAnywhere, Oracle, SQLAzure, and many others.
Development Time:
It is easy to learn and quickly developed, but there are some restrictions on the use of LINQ to SQL, which may cause problems when developing complex applications. EntityFramework is more powerful. Although learning and application are slower, more features are supported to minimize problems when developing complex applications.
Inheritance:
LINQ to SQL supports TPH, while EntityFramework supports TPH and TPT, and TPC is also partially supported.
File Type:
Using a database Markup Language (DBML) file that contains XML to map entity to a data table. EntityFramework uses four files. The first is Entity Data Model (EDMX), which is used in the designer. During compilation, the EDMX file generates three other files. In the other three files, the first is the ConceptualSchema Definition Language (CSDL) file, which contains the XML Definition of the conceptual model. The second is the SchemaDefinition Language (SSDL) file, which contains the definition of the storage model. The third file is the Mapping Specification Language (MSL) file, which contains the ing between the conceptual model and the storage model.
Complex types supported:
For example, a customer has a telephone number, but you want to define the telephone number as a country code, Region code, city code, number, and extension code. LINQto SQL does not support this complex type, but EntityFramework does.
Query capability:
Use DataContext to query databases. EntityFramework queries using ObjectContext through LINQto Entities. Entity Framework also provides ESQL, a query language similar to SQL, which is suitable for defining queries in model definitions. EntityFramework also contains the ObjectQuery class, which is used to dynamically create a query during the running of the object service. Finally, EntityFramework also contains EntityClientProvider, which is used to query the conceptual model.
Performance:
The first query executed by the LINQ to SQL and Entity Framework is slow, but the subsequent performance is satisfactory. EntityFramework has a slightly better performance than LINQto SQL.
Perfection:
Microsoft stops releasing new LINQ to SQL after the Entity Framework is released. However, due to the simplicity of LINQto SQL, it is still very popular, therefore, Microsoft will continue to provide support and feedback to users of LINQto SQL, but the new version of LINQto SQL will not be released.
Databases generated by models:
LINQ to SQL cannot generate databases by models. Entity Framework supports two types of development modes, database priority and encoding priority. Database development is preferred and the database already exists. Therefore, the model does not need to generate the database. Encoding is preferred. You must first create your model and then generate a database from the model.
Original article: http://blog.163.com/kunkun0921@126/blog/static/169204332201401605839384/