Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq2SQL vs EF in .net Framework 4.0

Tags:

So what's the verdict on these two products now? I can't seem to find anything regarding this issue SPECIFICALLY for VS2010/.net 4.0

Back in .net 3.5 days, most people believe Linq2SQL will be dead when .net 4.0 comes around, but it seems alive and well.

On the other hand, EF 4.0 seems to have gotten significant improvement.

For me, most of my work so far are small to medium sized projects, and my company is migrating from VS08 to VS10 soonish. What should I be looking at? Or really, should I spend the time studying EF4.0 or would it be time more well spent looking at nHibernate? (But back on topic, I'm really more interested in Linq2Sql - EF.)

Lastly, I am currently using entlib / unity, which framework is more friendly for dependency/policy injection?

Thanks in advance.

like image 913
Sleeper Smith Avatar asked Dec 01 '10 22:12

Sleeper Smith


People also ask

What is the difference between EF and LINQ?

Entity Framework is an object-relational mapping (ORM) framework for connecting C# code to external databases, usually SQL Server. LINQ is a query language embedded into C# and a set of extension methods in order to make it useful.

What is linq2sql?

LINQ to SQL is a component of . NET Framework version 3.5 that provides a run-time infrastructure for managing relational data as objects. Relational data appears as a collection of two-dimensional tables (relations or flat files), where common columns relate tables to each other.

What is the difference between ef6 and EF core?

EF 6 is a stable and mature ORM while EF Core is relatively new. Microsoft rebuilt EF Core from the ground up and removed many of the internal dependencies and providers that EF 6 had (like SQLClient). In the long run, that will make EF Core much more extensible and lighter weight.


1 Answers

Here are some reasons why Entity Framework (v4) is better:

1 - L2SQL is essentially obsolete

2 - L2SQL does not support POCO mapping, EF does.

3 - EF has more flexibility (code first, model first, database first). L2SQL has only 1.

4 - EF has support for SPROC -> POCO mapping

5 - EF has Entity-SQL, allowing you to go back to classic ADO.NET when required

6 - EF supports inheritance (TPT, TPH)

7 - EF goes hand-in-hand with Repository pattern, and deferred execution via IQueryable

8 - EF components (ObjectSet, ObjectContext) are easily mockable and allow for DI

I cannot think of any reason why new projects should use L2SQL.

Some might say "Well L2SQL is good for small projects, i can drag and drop and be done with it".

Well you can do that with EF4 as well, and you'll have more flexibility/support in the long run if you decide to modify/grow your project. So that is not an excuse.

HTH

like image 118
RPM1984 Avatar answered Oct 23 '22 12:10

RPM1984