实体框架与.NET 4.0之间的LINQ to SQL有什么区别? [英] What is the difference between Entity Framework and LINQ to SQL by .NET 4.0?

查看:132
本文介绍了实体框架与.NET 4.0之间的LINQ to SQL有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查专业ASP.NET MVC第二版,并实现了EF替换LINQ到SQL。我从第一本书中熟悉LINQ to SQL,但我对EF一无所知。无论如何,阅读代码,除了名字,似乎没有任何改变。相同的老版本库,相同的旧功能。

I was checking 2nd edition of Professional ASP.NET MVC and realized EF replaced LINQ to SQL. I am familiar to LINQ to SQL from the first book but I know nothing about EF. Anyway while reading the code, it seems like nothing has changed except the name. Same old repository classes, same old functions.

我做了一点研究。我知道LINQ不限于SQL。此外,EF不限于Microsoft系列SQL服务器。 在这个2年的问题中,人们对EF不满意,说它过于复杂和所有。但现在我在EF名下读取相同的代码。只有使用LINQ to SQL的ADO.NET实体模型生成类。有没有人能够清楚EF的特征,因为现在是事实上的ORM?

I did a little research. I know LINQ is not limited to SQL. Also EF is not limited Microsoft-family SQL servers. In this 2 year old question people are not happy with EF, saying it's overcomplicated and all. But now I'm reading same code under EF name. Only classes are generated with ADO.NET Entity Model insted of LINQ to SQL. Can anybody clear out the fuss about EF features since it's the de facto standart ORM now?

推荐答案

它们有点相似,可以以非常类似的方式使用代码,但它们有一些重要的区别。注意LINQ与LINQ to SQL不一样; EF也使用LINQ。一些显着的区别是:

They are somewhat similar, and can be used in a very similar way, code-wise, but they have some important differences. Note that "LINQ" is not the same thing as "LINQ to SQL"; the EF also uses LINQ. Some notable differences are:


  • LINQ to SQL主要是SQL Server,而不是像设计那样通过实现。如果您有兼容的ADO.NET提供程序,则EF旨在支持并支持多个数据库。

  • 开箱即用,LINQ to SQL对DB有一个非常糟糕的故事元数据更改。您必须从头开始重新生成部分模型,并且您将无法自定义。

  • EF支持多对多关系和继承的模型功能。 LINQ to SQL不直接支持这些。

  • 在.NET 3.5中,LINQ to SQL比支持SQL Server的功能要好得多。这在.NET 4中大都是不正确的;它们在这方面非常相似。

  • EF允许您选择Model First,DB First或Code First建模。 LINQ to SQL,开箱即用,真的只支持DB First。

  • LINQ to SQL is largely SQL Server only, not so much by design as by implementation. The EF is designed to support, and does support, multiple DBs, if you have a compatible ADO.NET provider.
  • Out of the box, LINQ to SQL has a very poor story for DB metadata changes. You have to regenerate parts of your model from scratch, and you lose customizations.
  • The EF supports model features like many-to-many relationships and inheritance. LINQ to SQL does not directly support these.
  • In .NET 3.5, LINQ to SQL had much better support for SQL-Server-specific functionality than the EF. This is mostly not true in .NET 4; they're fairly similar in that respect.
  • The EF lets you choose Model First, DB First, or Code First modeling. LINQ to SQL, out of the box, really only supports DB First.

这篇关于实体框架与.NET 4.0之间的LINQ to SQL有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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