LINQ to SQL vs Entity Framework

June 4th, 2009 by Sanguanchai

Compare 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.

33 Responses to “LINQ to SQL vs Entity Framework”

  1. Osellus Blogs » ORM Deep Dive Says:

    [...] 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 [...]

  2. Rakesh Jaiswal Says:

    This is very helpful to me, i was in search of this type of summery features and comparison.

  3. dp.bldr Says:

    Where’s the PerformanceReport link?

    Very comprehensive comparison. Can you link to where Linq 2 Sql won’t continue to improve?

  4. LINQ to SQL vs Entity Framework « vGurus Blog Says:

    [...] http://www.osellus.com/blogs/2009/06/04/linq-to-sql-vs-entity-framework/ [...]

  5. Sumit Pranav Says:

    Excellent article. Well written.

    Updates needed as it was written quite back. Anyway worth reading…

    I personally prefer Entity Data Model.

    Thanks!

  6. Sumit Pranav Says:

    Excellent article. Well written.

    Updates needed as it was written quite back. Anyway worth reading…

    I personally prefer Entity Data Model.

    Thanks!

  7. fast cash payday loans uk Says:

    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.

  8. teambuilding Says:

    I believe your weblog is nice! I found it on Bing today. I believe I will come back on day, thank you.

  9. Stanley Cistrunk Says:

    lez lan bunlar ne bole

  10. what is a hemroid Says:

    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 :)

  11. Vishnu Says:

    thanks a lot for ur article…. really its great understandable & described superb way….
    thanks for sharing….

  12. BG mail Says:

    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.

  13. yeah go shopping Says:

    I am glad to be a visitant of this staring website, regards for this rare information!

  14. Cleo Cardosa Says:

    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!

  15. Free Classified Ads UK Says:

    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.

  16. Virtual Private Servers Says:

    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.

  17. piano Says:

    I am glad to be a visitor of this stark web blog, thank you for this rare information!

  18. professioanls Says:

    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!

  19. Payday Loans Says:

    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!

  20. Gift ideas Says:

    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.

  21. internapoli city Says:

    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.

  22. tutto gratis Says:

    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.

  23. best cell phones Says:

    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!

  24. what causes toenail fungus Says:

    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!

  25. plumber Says:

    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!

  26. Inn Says:

    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.

  27. Who is service tools Says:

    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!

  28. Scientific Calculator Says:

    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!

  29. contratar iberbanda Says:

    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!

  30. rv repair Says:

    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!

  31. продажа колхоза Says:

    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

  32. Search Engine Says:

    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!

  33. foxglove plug plants Says:

    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!

Leave a Reply