Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4 vs LINQ to SQL, for small or medium-size apps, working with SQL Server

I've seen some discussion about L2S vs EF4 on Stack Overflow back in April, when VS2010 was launched, namely:

Dump Linq-To-Sql now that Entity Framework 4.0 has been released?

Is Entity Framework worth moving to for a new small app?

Now, after 6 months, presumably people have had more interacting with EF4, so I'm curious of fresh opinions, especially when considering working only with SQL Server.

I've used LINQ to SQL a lot, and only played a bit with EF4. I wouldn't mind jumping in and learning more EF4, I'm not convinced though that it's worth the extra complexity, if my app is only going to talk to SQL Server.

So, if you had some experience with both, and you were to start a new small or medium-size app today, with a SQL Server back-end, which one would you choose?

And, of course, why...

like image 840
Dan Dumitru Avatar asked Oct 29 '10 12:10

Dan Dumitru


People also ask

Which is better Entity Framework or LINQ to SQL?

LINQ to SQL allow you to query and modify SQL Server database by using LINQ syntax. Entity framework is a great ORM shipped by Microsoft which allow you to query and modify RDBMS like SQL Server, Oracle, DB2 and MySQL etc. by using LINQ syntax. Today, EF is widely used by each and every .

Which is faster LINQ or Entity Framework?

LINQ To SQL is slow for the first time run. After first run provides acceptable performance. Entity Framework is also slow for the first run, but after first run provides slightly better performance compared to LINQ To SQL.

Does Entity Framework use LINQ to SQL?

Entity Framework Core uses Language-Integrated Query (LINQ) to query data from the database. LINQ allows you to use C# (or your . NET language of choice) to write strongly typed queries.

Why we use LINQ instead of SQL?

SQL isn't broken, so why fix it? Why do we need another querying language? The popular answer is that LINQ is INtegrated with C# (or VB), thereby eliminating the impedance mismatch between programming languages and databases, as well as providing a single querying interface for a multitude of data sources.


2 Answers

It depends... :)

If you don't need any of the extra features added by EF, L2S is generally:

  • easier to get started with and work with,
  • does more straightforward translations from Linq queries to TSQL and supports translating more plain .net methods into TSQL whereas L2E relies on 'special' methods for things like date/time comparisons etc,
  • and has less runtime overhead due to the direct 1:1 mapping between tables and entity classes.

EF adds more features such as support for other RDBMSes and more complex mapping than plain 1:1, support for several different types of entity inheritance etc. That comes with a cost:

  • the runtime overhead is higher than for L2S,
  • writing linq queries against EF is slightly more likely to run into expressions that can not be translated into TSQL due to use of unsupported CLR methods, or that needs to use L2E's 'special methods', and
  • it can take a bit more time to get the head around EF models than L2S models due to the dual layers (storage model and conceptual model) and the mappings between them. Manual tweaking of the model file in an xml editor is not unusual.

In short:

  1. If your app is simple enough, you only need to support SQL Server, and your db schema / data model is clean enough so you don't need to do more advanced mapping then L2S is a great choice. Although it is unlikely that MSFT will add any new big features to it, that is not really necessary. It works great as it is and solves the problem it is supposed to solve. Lots of apps and websites (including this one) runs fine on L2S.
  2. If you need to support other DBs than SQL Server, or if your db schema doesn't match the object model you want, or you need other 'bigger' features from EF then you should use EF.
like image 124
KristoferA Avatar answered Nov 01 '22 21:11

KristoferA


The company I work for is a $2.5B to $3.0B solar manufacturing company. We're using L2S for all of our next generation manufacturing applications. It's not without its warts, but we've found it to be fast (contrary to what many think), nimble and very easy to work with. We have no regrets. It does everything we need it to do.

like image 23
Randy Minder Avatar answered Nov 01 '22 22:11

Randy Minder