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

前端 未结 5 1340
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 06:47

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 re

5条回答
  •  忘了有多久
    2021-02-13 07:18

    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.

提交回复
热议问题