As described earlier, LINQ to Entities applications work against a conceptual data model (EDM). All mappings between the languages and the databases go through the new EntityClient
mapping provider. The application no longer connects directly to a database, or sees any database-specific constructs. The entire application operates in terms of the higher-level EDM.
This means that you can no longer use the native database query language. Not only will the database not understand the EDM model, but also current database query languages do not have the constructs required to deal with the elements introduced by the EDM, such as inheritance, relationships, complex-types, and so on.
On the other hand, for developers who do not require mapping to a conceptual model, LINQ to SQL enables developers to experience the LINQ programming model directly over existing database schema.
LINQ to SQL allows developers to generate .NET classes that represent data. Rather than map to a conceptual data model, these generated classes map directly to database tables, views, stored procedures, and user defined functions. Using LINQ to SQL, developers can write code directly against the storage schema using the same LINQ programming pattern as was previously described for in-memory collections, Entities, or the Data Set, as well as for other data sources such as XML.
Compared to LINQ to Entities, LINQ to SQL has some limitations, mainly because of its direct mapping against the physical relational storage schema. For example, you can't map two different database entities into one single C# or VB object, and if the underlying database schema changes, this might require significant client application changes.
So, in a summary, if you want to work against a conceptual data model, use LINQ to Entities. If you want to have a direct mapping to the database from your programming languages, use LINQ to SQL.
The following table lists some of the features supported by these two data access methodologies:
Features |
LINQ to SQL |
LINQ to Entities |
---|---|---|
Conceptual Data Model |
No |
Yes |
Storage Schema |
No |
Yes |
Mapping Schema |
No |
Yes |
New Data Access Provider |
No |
Yes |
Non-SQL Server Database Support |
No |
Yes |
Direct Database Connection |
Yes |
No |
Language Extensions Support |
Yes |
Yes |
Stored Procedures |
Yes |
Yes |
Single-table Inheritance |
Yes |
Yes |
Multiple-table Inheritance |
No |
Yes |
Single Entity from Multiple Tables |
No |
Yes |
Lazy Loading Support |
Yes |
Yes |
We will use LINQ to SQL in this book, because we will use it in the data access layer, and the data access layer is only one of the three layers for a WCF service. LINQ to SQL is much less complex than LINQ to Entities, so we can still cover it in the same book with WCF. However, once you have learned how to develop WCF services with LINQ to SQL through this book, and have learned how to use LINQ to Entities through some other means, you can easily migrate your data access layer to using LINQ to Entities.