The choice between LINQ to SQL and ADO. NET Entity Framework

Source: Internet
Author: User

 

Original article: http://ramanisandeep.wordpress.com/2010/12/09/linq-to-sql-vs-ado-net-entity-framework/

 

The choice between LINQ to SQL and ADO. NET Entity Framework

 

I believe that many new ASP. NET users often cannot figure out which one should be selected between LINQ to SQL and ADO. NET Entity Framework?

The answer from Michael pizzo is as follows:

 

There are many similarities between LINQ to SQL and entity framwork, but they have their own characteristics that can be applied to different occasions:

 

1) LINQ to SQL

LINQ to SQL has features targeting "rapid development" against a Microsoft SQL Server database. think of LINQ to SQL as allowing you to have a stronugly-typed view of your existing database schema. LINQ to SQL supports a direct, 1:1 mapping of your existing database schema to classes; a single table can be mapped to a single inheritance hierarchy (I. E ., A table can contain persons, MERS MERs, and employees) and foreign keys can be exposed as stronugly-typed relationships. you can build LINQ queries over tables/views/table valued functions and return results as stronugly typed objects, and call stored procedures that return strongly typed results through stronugly typed methods.

 

A key design principle of LINQ to SQL is that it "just work" for the common cases; so, for example, if you access a collection of orders through the orders property of a customer, and that customer's orders have not previusly been retrieved, LINQ to SQL will automatically get them for you.

 

LINQ to SQL relies on convention, for example default insert, update, and delete logic through generated DML can be overwritten by exposing appropriately named methods (for example, "insertcustomer", "updatecustomer", "deletecustomer"). these methods may invoke stored procedures or perform other logic in order to process changes.

 

2) Entity Framework

The Entity Framework has features targeting "Enterprise scenarios". in an enterprise, the database is typically controlled by a DBA, the schema is generally optimized for storage considerations (performance, consistency, partitioning) rather than exposing a good application model, and may change over time as usage data and usage patterns evolve. with this in mind, the Entity Framework is designed around exposing an application-oriented data model that is loosely coupled, and may differ significantly, from your existing database schema. for example, you can map a single class (or "entity") to multiple tables/views, or map multiple classes to the same table/view. you can map an inheritance hierarchy to a single table/View (
In LINQ to SQL) or to multiple tables/views (for example, persons, MERS MERs, and employees cocould each be separate tables, where MERs and employees contain only the additional columns not present in persons, or repeat the columns from the persons table ). you can group properties into complex (or "composite") types (for example, a customer type may have an "address" property that is an address type with street, city, region, country and postal code properties ).

 

The Entity Framework lets you optionally represent values: inclurelationships directly, without representing the join table as an entity in your data model, and has a new feature called "defining query" that lets you expose any native query against the store as a "table" that can be mapped just as any other table (could t that updates must be stored med through stored procedures ). this flexible mapping, including the option to use stored procedures to process changes, is specified declaratively in order to account for the schema of the database evolving over time without having to recompile the application.

 

The Entity Framework includes des LINQ to entities which exposes attributes of the same features as LINQ to SQL over your conceptual application data model; you can build queries in LINQ (or in "Entity SQL ", A canonical version of SQL extended to support concepts like strong typing, polymorphism, relationship navigation and complex types), return results as stronugly typed CLR objects, execute stored procedures or table valued functions through stronugly-typed methods, and process changes by calling a single save method.

 

3) differences between LINQ to SQL and Entity Framework

However, the Entity Framework is more than LINQ to entities; it should des a "storage layer" that lets you use the same conceptual application model through low-level ADO. NET data provider interfaces using Entity SQL, and audio stream results as possibly hierarchical/polymorphic datareaders, saving the overhead of materializing objects for read-only scenarios where there is no additional logic business.

 

The Entity Framework works with Microsoft SQL Server and 3rd party databases through extended ADO. NET data providers, providing a common query language against different relational databases through either LINQ to entities or Entity SQL.

 

So while there is a lot of overlap, LINQ to SQL is targeted more toward rapidly developing applications against your existing Microsoft SQL Server schema, while the Entity Framework provides object-and storage-layer access to Microsoft SQL Server and 3rd party databases through a loosely coupled, flexible mapping to existing relational schema.

 

Thanks ~

 

ADO. NET Entity Framework

Http://msdn.microsoft.com/zh-cn/data/aa937709

 

The Microsoft ADO. NET Entity Framework is an object/relational mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write. using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as stronugly typed objects. the Entity Framework's ORM implementation provides services like change tracking, identity resolution, lazy loading, and query translation so that developers can focus on their application-specific business logic rather than the data access fundamentals.

High-level capabilities of the Entity Framework:

    • works with a variety of database servers (including Microsoft SQL Server, Oracle, and DB2)
    • includes a rich Mapping engine that can handle real-world database schemas and works well with stored procedures
    • provides integrated Visual Studio Tools to exactly ally create entity models and to auto-generate models from an existing database. new databases can be deployed from a model, which can also be hand-edited for full control
    • provides a code first experience to create entity models using code. Code first can map to an existing database or generate a database from the model.
    • integrates well into all. NET application programming models including ASP. net, Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), and WCF data services (formerly ADO. net Data Services)

The Entity Framework is built on the existing ADO. net Provider Model, with existing providers being updated additively to support the new entity framework functionality. because of this, existing applications built on ADO. net can be carried forward to the Entity Framework easily with a programming model that is familiar to ADO. NET developers.

 

 

Using the Entity Framework to write data-oriented applications provides the following benefits:

    • incluced development time: the Framework provides the core data access capabilities so developers can concentrate on application logic.
    • developers can work in terms of a more application-centric object model, including types with inheritance, complex members, and relationships. in. NET framework 4, the Entity Framework also supports persistence ignorance through plain old CLR objects (POCO) entities.
    • applications are freed from hard-coded dependencies on a participant data engine or storage schema by supporting a conceptual model that is independent of the physical/storage model.
    • mappings between the object model and the storage-specific schema can change without changing the application code.
    • language-integrated query support (called LINQ to entities) provides intelliisense and compile-time syntax validation for writing queries against a conceptual model.

The Entity Framework uses the Entity Data Model (EDM) to describe the application-specific object or "conceptual" model against which the developer programs. the EDM builds on the widely known entity relationship model (introduced by Dr. peter Chen) to raise the specified action level above logical database schemas. the EDM was developed with the primary goal of becoming the Common Data Model Modeling ss a suite of developer and server technologies from Microsoft. thus an EDM created for use with the entity framework can also be leveraged with WCF data services (formerly ADO. NET data services), Windows azure table Storage, Sharepoint 2010, SQL Server reporting services, and SQL Server workbook for excel, with more coming in the future.

 

 

Complete!

 

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.