Linq to Entities and Linq to SQL

I've just about finished reading the ADO.NET Entity Framework Overview document and have been playing with Linq, Xlinq, Dlinq (apologies for no political correctness in what these are all called now).

One thing i don't quite get is why the distinction between ADO.Net entities (Linq to Entities) and Linq to SQL - other than for historical reasons. Now i think i grasp the intentions and purposes of both (disclaimer : i haven't read all the docs about dLinq quite yet!), but why they are defined as being different is a little confusing for me.

Would Linq to SQL not be regarded as conceptual "Linq to Entity" - that is ADO.Net entity over a single table? In other words, although they operate on a slightly different basis, should I, as a consumer of the entities really care?

It just (at the moment) seems they have different sources, but ultimately Linq to SQL is a subset of the more general Linq to Entities. And if this is the case then paragraph 4.4 may lead to some confusion.

However, others may see this differently, so glad to hear if they do (or there is more to it than i think!).

steven
http://stevenR2.com

[1249 byte] By [StevenR2] at [2008-2-7]
# 1

Since LINQ to Entities is relatively new, I haven't had a chance to dig into it too much yet. As I understand it, though the main thing LINQ to Entites gives you (over LINQ to SQL) is the ability to flatten table relations. In order to do this, there is a mapping process between the eSQL and the underlying TSQL for the individual tables that need to be modified. Even if only one table is used (as is the case of LINQ to SQL), the runtime would need to parse your LINQ to Entity statement into eSQL (using the expression trees) and then map from the eSQL into TSQL statements to send to the database for execution.

In the case that you don't need the entity mapping portion (ie. for simple admin/utility forms where the conceptual model maps directly to the table structures), LINQ to SQL may suffice and offer less overhead and thus better performance.

Another consideration is dynamic queries. LINQ shines when using declaritive syntax. When moving to dynamic queries, things get a bit more tricky (dynamically building expression trees is as fun as working with the codedom). eSQL allows you to build your queries as strings (you loose some of the strong typing) and pass that on as you would a standard LINQ to Entities statement.

Jim Wooley
http://devauthority.com/blogs/jwooley

jwooley at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 2

From clearing up mapping technologies in .NET vNext. The problem domain your application targets has a mismatch with the already existing data model. In this case, the ADO.NET Entity Framework is the right choice.

The existing data model matches the problem domain your application targets. You don’t require mapping between these two models. Linq to SQL lets you directly map to your existing or new data model.

PaulGielens at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 3
I don't see a purpose for DLinq / Linq for Sql: it is surpassed in every way by Linq for entities. IMHO, Ms keeps it around, for now, to not dissapoint the Linq folks at the C# team, at least that's my impression.
FransBouma-C#MVP at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 4
jwooley wrote:

Since LINQ to Entities is relatively new, I haven't had a chance to dig into it too much yet. As I understand it, though the main thing LINQ to Entites gives you (over LINQ to SQL) is the ability to flatten table relations. In order to do this, there is a mapping process between the eSQL and the underlying TSQL for the individual tables that need to be modified.


No that's not the case. Linq to entities converts Linq's Expression trees into an intermediate format, which is the same format as the eSql consumer converts to,
so there's no conversion to eSql first.

In the case that you don't need the entity mapping portion (ie. for simple admin/utility forms where the conceptual model maps directly to the table structures), LINQ to SQL may suffice and offer less overhead and thus better performance.

No, there's no extra overhead. Linq to sql (DLinq) is doing o/r mapping as much as Linq to entities does so there's no difference. That's the odd part.

Another consideration is dynamic queries. LINQ shines when using declaritive syntax. When moving to dynamic queries, things get a bit more tricky (dynamically building expression trees is as fun as working with the codedom). eSQL allows you to build your queries as strings (you loose some of the strong typing) and pass that on as you would a standard LINQ to Entities statement.

This is indeed a good point, and also shows why DLinq has no real purpose.

FransBouma-C#MVP at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 5

Frans Bouma - C# MVP wrote:
I don't see a purpose for DLinq / Linq for Sql: it is surpassed in every way by Linq for entities. IMHO, Ms keeps it around, for now, to not dissapoint the Linq folks at the C# team, at least that's my impression.

What if I'd choose to skip the level of indirection that conceptual views bring to my application? Assuming a straightforward mapping is sufficient. Thus: object-edm-target vs. object-target.

PaulGielens at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 6
Paul Gielens wrote:

What if I'd choose to skip the level of indirection that conceptual views bring to my application? Assuming a straightforward mapping is sufficient. Thus: object-edm-target vs. object-target.

A default mapping from a db schema to the EF would be enough... The main issue to achieve it today is that you need the .xml files + the generated classes in the EF vs just the generated classes in LinQToSQL, so is a little more troublesome, but if the EF supports mapping through attributes in addition to mapping using xml files, then it would be the same thing.

Regards,

Andres

AndresAguiar at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 7

We're looking at default mapping semantics for the product, they just weren't included in the August CTP. The goal here is to provide the conceptual layer for those who need it, but stay out of the way for those who don't.

-Lance

LanceOlson-MSFT at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...
# 8

jwooley wrote:

Since LINQ to Entities is relatively new, I haven't had a chance to dig into it too much yet. As I understand it, though the main thing LINQ to Entites gives you (over LINQ to SQL) is the ability to flatten table relations. In order to do this, there is a mapping process between the eSQL and the underlying TSQL for the individual tables that need to be modified.


Franz said:

>No that's not the case. Linq to entities converts Linq's Expression trees into an intermediate format, which is the same format as the eSql consumer converts to,
so there's no conversion to eSql first.

Ah, thanks for the clarification. That does indeed make more sense from a framework standpoint. It would mean that the teams are working together more than I had given them credit. I did not catch skipping the need for eSQL with LINQ to Entities and doing the direct translation via the Expression Trees. I need to play with it more to get a better hand on it I suppose.

Jim

jwooley at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,ADO.NET Orcas...

Visual Studio Orcas

Site Classified