简体   繁体   English

从 NHibernate 迁移到实体框架 4.1?

[英]Migration from NHibernate to Entity Framework 4.1?

I am aware that this question may be a little bit dangerous to ask, but I really need some opinion with this.我知道这个问题问起来可能有点危险,但我真的需要一些意见。

We've got our system, it's an website (will be popular web portal, we use MVC3) and before I was here rest of my co-woorkers chose NHibernate as their OR Mapper solution, and they started to write criteria queries and such..我们有我们的系统,它是一个网站(将是流行的 web 门户,我们使用 MVC3),在我来到这里之前,我的同事的 rest 选择了 Z111BBE34492093E9894EF9E8B3E 来编写他们的标准和地图查询等解决方案。0 .

Right now the team is closer to Linq approach, so we tried to wrote queries in built-in Linq provider.. The thing is.. it's horribly adapted - literally you cannot write non-trivial query and do not get Not supported exception ...现在团队更接近 Linq 方法,所以我们尝试在内置的 Linq 提供程序中编写查询。问题是......它非常适应 - 从字面上看,你不能编写非平凡的查询,也不会得到Not supported exception 。 .

We decided that it's the last possible moment, to change our OR Mapper to something more Linq-based and we since the EF4.1 got ultrafriendly Code First option, we are decided that this is what we need.我们决定这是最后一刻,将我们的 OR Mapper 更改为更基于 Linq 的东西,并且自从 EF4.1 获得超友好的 Code First 选项以来,我们决定这就是我们所需要的。

The problem that I need some opinions on it is worth the time to migrate from NHibernate to EF4.1... The project will last at least one year further in development, so we have a lot of work to do, and we want to do it in nice and non-frustrating way..我需要一些意见的问题值得花时间从 NHibernate 迁移到 EF4.1... 该项目将持续至少一年的进一步开发,所以我们有很多工作要做,我们想要以良好且不令人沮丧的方式做到这一点..

Some facts:一些事实:

  • We have about 50 entities in our project我们的项目中有大约 50 个实体
  • We have about 160 queries written in Criteria API (all covered in unit tests)我们有大约 160 个用 Criteria API 编写的查询(全部包含在单元测试中)
  • We need to have composite, inheritance and many-many support我们需要复合,inheritance 和多对多支持
  • The project will be twice as big as it is now该项目将是现在的两倍
  • We are not satisfied with our database performance我们对我们的数据库性能不满意
  • We hate the way that we write queries right now!我们讨厌我们现在编写查询的方式!

So.. now.. is migration a good or bad idea?所以..现在..迁移是个好主意还是坏主意? Will EF resolve our problems, will it make us happy or that step will be just the waste of our time? EF 会解决我们的问题吗?它会让我们开心吗?还是这一步只是浪费我们的时间?

Regards问候

Be aware that you will exchange better linq support for worse mapping functionality and sometimes much worse performance ( inheritance queries , no query or command batching , ...).请注意,您将交换更好的 linq 支持以获得更差的映射功能,有时甚至更差的性能( inheritance 查询无查询或命令批处理,...)。 Now return to the blackboard and think again.现在回到黑板上再想一想。 If you don't like your database performance now, it will hardly improve with EF.如果您现在不喜欢您的数据库性能,EF 几乎不会改善它。

I guess it is little bit late to change the technology - it will have high cost.我想改变技术有点晚了——成本会很高。 But anyway if you really want to do it why not to make proof-of-concept where you take some really complex mapped feature with some advanced queries and try to do the same in EF code first?但是无论如何,如果您真的想这样做,为什么不进行概念验证,在其中使用一些非常复杂的映射功能和一些高级查询并尝试首先在 EF 代码中做同样的事情呢? You can test the same just in simple console application and compare both mapping experience and queries + performance.您可以在简单的控制台应用程序中进行相同的测试,并比较映射体验和查询 + 性能。

Performance is perhaps not an issue at the moment but it can be something you really have to optimize in the future and EF will provide you much less features for that.性能目前可能不是问题,但它可能是您将来真正需要优化的东西,EF 将为您提供更少的功能。 If you want to improve performance of EF solution you very often revert back to native SQL and stored procedures.如果您想提高 EF 解决方案的性能,您通常会恢复到原生 SQL 和存储过程。 Do you thing that it will have better experience for writing queries?你认为它在编写查询方面会有更好的体验吗?

I have to agree with @Ladislav, EF and LINQ is nice it just works compared to NHibernate LINQ, however the SQL EF generates sometimes is pretty terrible and is not terribly performant and you will be forced to recode complex queries into views and SP's etc. Nhibernate also can fall into this trap however having many different options is a benefit as you can cherry pick the best one to suit your needs. I have to agree with @Ladislav, EF and LINQ is nice it just works compared to NHibernate LINQ, however the SQL EF generates sometimes is pretty terrible and is not terribly performant and you will be forced to recode complex queries into views and SP's etc. Nhibernate 也可能落入这个陷阱,但是有许多不同的选项是一个好处,因为您可以挑选最适合您需求的选项。

I suppose you are looking at balancing the following:-我想您正在考虑平衡以下内容:-

  1. rewrite using EF and then revisting ugly/slow generated SQL into more performant database queries使用 EF 重写,然后将生成的丑陋/缓慢的 SQL 修改为性能更高的数据库查询
  2. use NHibernate and drop LINQ for anything too complex into Criteria/QueryOver/HQL使用 NHibernate 并将 LINQ 用于任何过于复杂的 Criteria/QueryOver/HQL

Kinda jumping from one ORM into another can be like jumping from the frying pan into the fire.从一个 ORM 跳到另一个就像从煎锅跳到火里一样。 Both have their sweet spots both will burn your fingers!两者都有他们的甜蜜点,都会烧伤你的手指!

Personally I also come across the issues with the linq provider for Nhibernate.我个人也遇到了 Nhibernate 的 linq 提供程序的问题。

However, I chose to stick with NHibernate because of its "proper" SQL-generation, overall performance and extensibility.但是,我选择坚持使用 NHibernate,因为它“正确”的 SQL 生成、整体性能和可扩展性。

The latter allows you to alleviate your RDBMS with a 2nd level cache of your choice, such as MemcacheD.后者允许您使用您选择的二级缓存(例如 MemcacheD)来减轻您的 RDBMS。 It keeps the objects in-memory (on the MemcacheD server) fetching/committing them from/to the RDBMS only if needed.它仅在需要时将对象保存在内存中(在 MemcacheD 服务器上)从/向 RDBMS 获取/提交它们。 Also applies to compiled SQL-queries.也适用于已编译的 SQL 查询。

Well to be honest it sounds like you've already made up your mind.老实说,听起来你已经下定决心了。 I'm not sure what you are really asking here.我不确定你在这里真正问的是什么。 If you are interested in sticking with NHibernate you should ask specific questions on problems you are having.如果您有兴趣坚持使用 NHibernate,您应该就您遇到的问题提出具体问题。

In my opinion if your team is more familiar with EF then you should switch.在我看来,如果您的团队更熟悉 EF,那么您应该切换。 If they aren't then I'm not sure if you will ever know if the EF will solve all of your problems unless you actually outline the specific problems you are having.如果不是,那么我不确定您是否会知道 EF 是否会解决您的所有问题,除非您实际上概述了您遇到的具体问题。

Did you try Fluent NHibernate?您是否尝试过 Fluent NHibernate? http://fluentnhibernate.org/ . http://fluentnhibernate.org/ You can use LINQ with it.您可以将 LINQ 与它一起使用。 I used it in a project and it worked very well.我在一个项目中使用它,效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM