LINQ to SQL vs Entity Framework
June 4th, 2009 by SanguanchaiCompare features for LINQ to SQL vs Entity Framework
| Feature | LINQ to SQL | Entity Framework |
| Model | domain model | conceptual data model |
| Databases Supported | SQL server only | variety of databases |
| Data Sources | tables only | tables, replication, reporting Services, BI and etc |
| Complexity | simple to use | complex to use |
| Development Time | rapid development | slower development but more capabilities |
| Mapping | class to single table | class to multiple tables |
| Inheritance | hard to apply | simple to apply |
| File Types | dbml file only | after compilation generate edmx file with 3 sections to represent the schema: csdl, msl and ssdl |
| Create complex properties (e.g. Customer type may have Address property that is an Address type with Street, City, Region, Country and Postal code properties) | Not Support | Support in VS2010 Beta 1 but we can manually modify in .edmx file. |
| Query | 1. LINQ to SQL (for select) 2. Data Context (for update, create, delete, store procedure, view) |
1. LINQ to Entities (for select)2. Entity SQL (is a derivative of Transact-SQL, it supports inheritance and associations)
3. Object Services (for update, create, delete, store procedure, view) 4. Entity Client (is an ADO.NET managed provider, it is similar to SQLClient, OracleClient, etc. It provides several components like EntityCommand, EntityTransaction)
|
| Can synchronize with Database if Database Schema is changed | Not Support | Support |
| Performance | Very slow for the first query | Very slow for the first query. But overall performance is better than LINQ to SQL (Please see the result in the attach file) |
| Continue to improve features in the future | No | Yes |
| Generate database from entity model | Not Support | It will support in VS2010 Beta1. |
Limitation for Entity Framework in VS2008 SP1
1. It will throw error in runtime if we use Contains statement. For example,
from p in context.Yard_Projects
where p_projectIDs.Contains(p.ProjectID)
select p
2. It will not generate method that map to store procedure that are not return as entity type. (We need to Entity Client to execute store procedure.) For example,
Void DeleteProjects(@CSVProjectIDs)
3. We need to map every column of a table in the storage schema. If some columns are not mapped, it will compile error.
4. If we delete a type from diagram, it’s difficult to put it back. We may manually update in .edmx file or delete old one and generate new model.
5. You don’t get a lot of control over the storage schema at all. What you mostly see is the client schema and the mapping to the storage schema.
6. If you want create methods that are map to store procedure that has the result from multiple tables, we need to manually modify section “SSDL” in the .edmx file.
Performance Test
I tried to test on LINQ to SQL and Entity Framework, I found the overall performance Entity Framework is better than LINQ to SQL. I separated test cases into 2 test groups.
1. Test select/create/update/delete for single table. You can see my test result in the “TestForSingleTable” sheet.
2. Test select/create/update/delete for single table with many associations. You can see my test result in te “TestForManyAssociation” sheet.
You can see the performance report in the link, PerformanceReport
Recommendation
I think we should use Entity Framework than LINQ to SQL because many reasons as follows.
1. It is more flexible to mapping entity model to database. You can map one class to multiple tables, using inheritance.
2. It supports many queries, you can use LINQ to Entities, Entity SQL, Object Services and Entity Client.
3. When the database schema is changed, you can synchronize entity model from latest database.
4. It has better overall performance when compare with LINQ to SQL.
5. It will be improved many features in the VS2010. You will create complex data type, generate database from entity model.
6. It supports many database vender other than SQL Server.
But disadvantage of using Entity Framework may be complexity and development time.
Refer to my performance report, if we use Entity Framework to implement in the data layer, we should use the following patterns.testperformancelinqtosql_entityframework
1. Use LINQ to Entity for simple queries.
2. Use Entity Client or Object to execute Store Procedure for complex queries (many joins, groups) or queries that perform delete many entities with contains many associations.
3. Use Object Service to insert, update, delete single/multiple entities.

June 5th, 2009 at 4:51 pm
[...] can take a look at his findings in the post he published yesterday - LINQ to SQL vs Entity Framework. No doubt there are other architects and developers out there trying to get a handle on the same [...]
June 25th, 2009 at 12:00 pm
This is very helpful to me, i was in search of this type of summery features and comparison.
January 30th, 2010 at 2:13 pm
Where’s the PerformanceReport link?
Very comprehensive comparison. Can you link to where Linq 2 Sql won’t continue to improve?
February 2nd, 2010 at 7:32 pm
[...] http://www.osellus.com/blogs/2009/06/04/linq-to-sql-vs-entity-framework/ [...]
December 17th, 2010 at 8:39 am
Excellent article. Well written.
Updates needed as it was written quite back. Anyway worth reading…
I personally prefer Entity Data Model.
Thanks!
December 17th, 2010 at 8:39 am
Excellent article. Well written.
Updates needed as it was written quite back. Anyway worth reading…
I personally prefer Entity Data Model.
Thanks!
April 23rd, 2011 at 6:01 am
This is exactly i will be seeking. Here is what I call value. The data provided right here should be to the greatest. I need to say you need to have invested your time in putting these content jointly. These are relevant to your product. I will suggest this to the world and also to all my friends. I will get back here to examine the quantity of work. Thank you for making this take place.
April 23rd, 2011 at 1:44 pm
I believe your weblog is nice! I found it on Bing today. I believe I will come back on day, thank you.
May 26th, 2011 at 8:31 am
lez lan bunlar ne bole
June 2nd, 2011 at 1:15 am
Fantastic weblog, companion! Osellus Blogs » LINQ to SQL vs Entity Framework is actually one thing. We are introducing my very own shortly i will really duplicate areas of yours, legally of course
July 12th, 2011 at 7:59 am
thanks a lot for ur article…. really its great understandable & described superb way….
thanks for sharing….
October 7th, 2011 at 7:15 pm
What’s Going down i’m new to this, I stumbled upon this I’ve discovered It absolutely helpful and it has helped me out loads. I’m hoping to give a contribution & help other users like its helped me. Great job.
October 9th, 2011 at 7:17 am
I am glad to be a visitant of this staring website, regards for this rare information!
October 9th, 2011 at 5:37 pm
That is the fitting weblog for anyone who needs to search out out about this topic. You understand so much its nearly exhausting to argue with you (not that I actually would want…HaHa). You positively put a brand new spin on a topic thats been written about for years. Nice stuff, simply nice!
October 29th, 2011 at 10:43 am
I was very happy to seek out this web-site.I needed to thanks on your time for this wonderful read!! I positively having fun with each little bit of it and I have you bookmarked to check out new stuff you weblog post.
November 5th, 2011 at 8:54 am
Thank you for another informative web site. Where else may I get that type of information written in such a perfect way? I have a mission that I’m just now operating on, and I’ve been at the glance out for such information.
November 6th, 2011 at 6:04 am
I am glad to be a visitor of this stark web blog, thank you for this rare information!
November 11th, 2011 at 12:04 pm
Once I originally commented I clicked the -Notify me when new comments are added- checkbox and now every time a remark is added I get 4 emails with the identical comment. Is there any approach you’ll be able to take away me from that service? Thanks!
November 12th, 2011 at 6:10 pm
Wow, marvelous blog layout! How long have you been running a blog for? you make blogging look easy. The total look of your web site is fantastic, as neatly as the content material!
November 15th, 2011 at 9:50 am
I’ve recently started a website, the information you offer on this web site has helped me greatly. Thank you for all of your time & work.
November 20th, 2011 at 8:13 am
I want to express appreciation to this writer just for rescuing me from this type of condition. After researching through the the web and seeing things which were not productive, I believed my entire life was over. Existing devoid of the solutions to the problems you have resolved by means of your main blog post is a critical case, as well as those that could have badly affected my career if I hadn’t discovered your blog post. Your primary know-how and kindness in handling a lot of stuff was invaluable. I’m not sure what I would’ve done if I hadn’t encountered such a step like this. I am able to at this point look ahead to my future. Thanks so much for this high quality and result oriented help. I will not hesitate to suggest your blog to any individual who should get guidance about this subject.
November 23rd, 2011 at 6:55 am
I’ll immediately grab your rss feed as I can not to find your email subscription hyperlink or newsletter service. Do you have any? Please let me understand in order that I may just subscribe. Thanks.
November 23rd, 2011 at 7:11 am
magnificent publish, very informative. I wonder why the opposite specialists of this sector don’t notice this. You should proceed your writing. I am confident, you’ve a huge readers’ base already!
November 30th, 2011 at 6:08 am
I’d must check with you here. Which is not one thing I often do! I take pleasure in reading a put up that may make folks think. Additionally, thanks for permitting me to remark!
December 2nd, 2011 at 11:20 am
I do not even know the way I finished up right here, however I believed this post was once great. I don’t know who you might be but certainly you are going to a famous blogger when you aren’t already
Cheers!
December 7th, 2011 at 7:24 am
Thank you for all your valuable labor on this web site. My aunt take interest in working on research and it’s really simple to grasp why. All of us notice all about the compelling method you produce effective secrets on this blog and in addition attract participation from other ones on this subject matter plus our daughter is certainly starting to learn a great deal. Take pleasure in the remaining portion of the year. You are performing a really good job.
December 7th, 2011 at 12:12 pm
What i do not realize is in truth how you’re no longer actually a lot more smartly-favored than you might be right now. You’re so intelligent. You realize thus considerably in relation to this topic, produced me in my view believe it from a lot of varied angles. Its like men and women are not interested until it is one thing to accomplish with Girl gaga! Your personal stuffs excellent. Always deal with it up!
December 8th, 2011 at 8:59 pm
I’d must verify with you here. Which isn’t something I often do! I take pleasure in reading a post that can make folks think. Also, thanks for permitting me to remark!
December 11th, 2011 at 6:55 am
What i do not realize is actually how you are no longer really much more well-preferred than you may be right now. You are so intelligent. You realize thus considerably in terms of this subject, made me for my part believe it from numerous numerous angles. Its like women and men aren’t fascinated unless it is one thing to accomplish with Girl gaga! Your personal stuffs excellent. All the time handle it up!
December 14th, 2011 at 7:53 am
Wow, superb blog layout! How lengthy have you been running a blog for? you make blogging glance easy. The overall look of your website is wonderful, as smartly as the content!
December 17th, 2011 at 3:09 pm
I get pleasure from, result in I discovered just what I used to be taking a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye
December 17th, 2011 at 6:30 pm
Wow, fantastic blog format! How lengthy have you ever been running a blog for? you made running a blog look easy. The full glance of your site is great, as neatly as the content material!
December 21st, 2011 at 8:12 am
You really make it seem really easy together with your presentation but I to find this topic to be actually one thing which I think I would by no means understand. It seems too complex and extremely huge for me. I’m looking ahead in your next put up, I’ll attempt to get the dangle of it!