实体框架4对LINQ to SQL,适用于使用SQL Server的中小型应用程序 [英] Entity Framework 4 vs LINQ to SQL, for small or medium-size apps, working with SQL Server

查看:96
本文介绍了实体框架4对LINQ to SQL,适用于使用SQL Server的中小型应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

4月,当VS2010推出时,我已经看到有关L2S vs EF4在Stack Overflow上的讨论,即:



现在,实体框架4.0已经发布了Linq-To-Sql ?



实体框架值得转移到一个新的小应用程序?



现在,6个月后,大概有与EF4有更多的互动,所以我很好奇的新鲜意见,特别是当考虑只使用SQL Server时。



我已经使用了LINQ to SQL,只用EF4打了一下。我不会介意跳入和学习更多的EF4,我不相信这是值得的额外的复杂性,如果我的应用程序只是要谈SQL Server。



所以,如果你有两个经验,而你今天要启动一个新的中小型应用程序,一个SQL Server后端,你会选择哪一个?



当然,为什么...

解决方案

它取决于...:)



如果您不需要EF添加任何额外功能,则L2S通常为:




  • 更容易开始使用,

  • 更简单地将Linq查询转换为TSQL,并支持将更简单的.net方法转换为TSQL,而L2E依赖于特殊方法对于诸如日期/时间比较等的事情,

  • ,由于表和实体类之间的直接1:1映射,运行时间较少。



EF增加更多功能res,例如支持其他RDBMS,并且比普通的1:1更复杂的映射,支持几种不同类型的实体继承等。带有成本:




  • 运行时开销高于L2S,

  • 编写针对EF的linq查询稍微更有可能运行到由于使用不支持而无法转换为TSQL的表达式CLR方法,或需要使用L2E的特殊方法

  • 由于双层(存储模型和概念模型)和它们之间的映射,可以花更多的时间来获得围绕EF模型的头衔,而不是L2S模型。在xml编辑器中手动调整模型文件是不寻常的。



简而言之:


  1. 如果你的应用程序很简单,你
    只需要支持SQL Server,而
    你的数据库模式/数据模型是干净的
    足够你不需要做更多
    高级映射,那么L2S是一个伟大的
    选择。虽然
    MSFT不太可能添加任何新的大功能
    ,但这并不是真的必要的。
    它的工作原理很好,解决了
    应该解决的问题。许多应用程序和网站(包括这个)在L2S上运行正常。

  2. 如果您需要支持其他DB
    比SQL Server,或者如果您的db
    模式不符合您想要的对象
    模型,或者您需要其他
    '较大'功能从EF然后您
    应该使用EF。


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

解决方案

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.

这篇关于实体框架4对LINQ to SQL,适用于使用SQL Server的中小型应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆