我应该使用什么标准来评估 ORM?
这里有很多问题询问“我应该对 x 和 y 使用什么 ORM”,但我没有看到任何专门询问如何选择一个的问题。相关:为什么应该使用 ORM?、我应该为 ASP.Net MVC 使用什么 ORM项目?,是否有充分的理由不使用ORM?等等。
世界上有很多 ORM。我想了解如何比较它们。我听说过诸如活动记录模型和域模型之类的东西,但我不确定它们是什么意思。那么,我可以使用哪些好的标准来将一个 ORM 与另一个 ORM 进行比较呢?
如果您想知道的话,我们的环境是 C#、MVC、SQL Server。
There are plenty of questions on here that ask 'what ORM should I use with x and y' but I didn't see any that specifically asked how to pick one. Related: Why should you use an ORM?, What ORM should I use for a ASP.Net MVC project?, Are there good reasons not to use an ORM? and more.
There are a lot of ORMs out there in the world. I'd like to get an idea of how to compare them. I've heard about things like active record model and domain model among others and I'm not sure what those mean. So what are a good set of criteria I can use to compare one ORM to another?
Our environment, in case you're wondering, is C#, MVC, SQL Server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(如果可能的话,我尝试以非 .NET 特定的方式来回答。)
选择 ORM 最重要的标准是您的业务需求。
我想说另一个重要的标准是您对 ORM 未来可持续性的信念。微软倾向于每两年左右改变他们的数据访问技术,所以我想说实体框架的未来尚不清楚。 NHibernate 可能会走与 NUnit 相同的道路——当微软发布 MSTest 时,NUnit 一度陷入停滞,但现在 NUnit 再次势头强劲,因为微软大多忽视了 MSTest。你必须在这里得出自己的结论,现在微软似乎对实体框架给予了一些喜爱,但据我所知它仍然不能很好地处理枚举,而且我还没有听说这种情况什么时候会改变。
另一个标准是您是否偏好开源技术、Microsoft 技术或商业第三方技术。
在某些时候,ORM 的功能会很重要。您可能需要使用多个 ORM 对场景进行原型设计,以确定 ORM 的功能(和/或性能)是否符合您的要求。 NHibernate 是 .NET 领域中功能最丰富的 ORM。
您需要支持某个数据库供应商吗?选择一种支持您关心的 ORM。 SQL Server 是 .NET 世界中支持最广泛的数据库供应商。
您更倾向于代码优先设计还是数据库优先设计?选择一种支持您关心的 ORM。
您在活动记录、存储库和其他内容之间有偏好吗?选择一种支持您关心的 ORM。
我回答了下面链接的有关选择 .NET ORM 的问题,部分是通过提供人们在 StackOverflow 上询问应该使用哪种 .NET ORM 的链接来实现的。阅读其他答案可以获得很多价值。
NHibernate、实体框架、活动记录或 linq2sql
没有人正确的答案也不是一套正确的选择标准。您的业务需求是需要考虑的最重要因素。
(I tried to answer in a non-.NET specific way when possible.)
The most important criteria for choosing an ORM are your business requirements.
I would say another important criteria is your belief in the future sustainability of the ORM. Microsoft has a tendency to change their data access technology every two years or so, so I would say Entity Framework's future is unclear. NHibernate may follow the same path as NUnit - when Microsoft released MSTest, NUnit languished for a while, but now NUnit has momentum again since Microsoft is mostly neglecting MSTest. You have to reach your own conclusion here, right now Microsoft appears to be giving Entity Framework some love, yet as far as I know it still doesn't handle enums very well and I haven't heard when that may change.
Another criteria is whether you have a preference between open source technologies or technologies from Microsoft or commercial third party technologies.
At some point, the features of the ORM will matter. You may need to prototype your scenario with multiple ORMs to determine if the features (and/or performance) of the ORM match your requirements. NHibernate is the most feature rich ORM in the .NET space.
Do you need to support a certain database vendor? Pick an ORM that supports the one you care about. SQL Server is the most widely supported database vendor in the .NET world.
Do you have a preference between code first or database first design? Pick an ORM that supports the one you care about.
Do you have a preference between active record vs. repository vs. something else? Pick an ORM that supports the one you care about.
I answered the question linked below about choosing a .NET ORM partially by providing links to all the times people asked which .NET ORM they should use on StackOverflow. There is a lot of value that can be gained from reading those other answers.
NHibernate, Entity Framework, active records or linq2sql
There is no one right answer nor one correct set of criteria for choosing. Your business requirements are the most important ingredient to consider.