使用MVC从头开始创建网站,哪个ORM更好,EF还是NHibernate?

时间:2022-01-20 16:58:42

I want to create a website, with many users and obviously with a big amount of database, and I do not have experience in either EF or NHibernate, what is recommended one for me?

我想创建一个网站,有很多用户,显然有大量的数据库,我没有EF或NHibernate的经验,我建议使用什么?

5 个解决方案

#1


4  

EF is very well integrated with .NET and Visual Studio. Gives you a very good designer inside Visual Studio, and leverage LINQ to write queries that are very easy to read.

EF与.NET和Visual Studio非常完美地集成在一起。在Visual Studio中为您提供了一个非常优秀的设计器,并利用LINQ编写非常易于阅读的查询。

For me, this is a no-brainer. I would go with EF4 without a doubt.

对我来说,这是一个明智的选择。毫无疑问,我会选择使用EF4。

#2


1  

If you are doing first time I would recommend you to go with EF because its easy to paly with it no more configuration and hidden properties....no need to apply any extra efforts just add the object and your task is done.

如果你是第一次做我会建议你去EF,因为它很容易与它配合,没有更多的配置和隐藏属性....不需要任何额外的努力只需添加对象,你的任务就完成了。

but if you are looking better performance go for NHibernate.

但如果你看起来更好的表现去NHibernate。

#3


1  

The answer depends on which database you're using on the backend. If you're using any of the Microsoft databases then EF is the way to go.

答案取决于您在后端使用的数据库。如果您使用的是任何Microsoft数据库,那么EF就是您的选择。

Oracle doesn't have a client that supports EF yet (it is coming), so you'll need to use NHibernate to talk to Oracle until they update their client.

Oracle还没有支持EF的客户端(即将推出),所以在更新客户端之前,您需要使用NHibernate与Oracle通信。

#4


0  

I'd go for NHibernate, because it allows you to tweak performance better than EF and is better portable across different databases.

我会选择NHibernate,因为它可以让你比EF更好地调整性能,并且可以在不同的数据库中更好地移植。

When using asp.net mvc for the first time, you can consider using S#arp architecture. It uses NHibernate. On the website it is explained clearly how to get started quickly.

当您第一次使用asp.net mvc时,您可以考虑使用S#arp架构。它使用NHibernate。在网站上,它清楚地解释了如何快速入门。

#5


0  

Neither.

都不是。

I've used EF for the past year and the problems i've had are not worth the hassle.

我过去一年都使用EF,而且我遇到的问题不值得麻烦。

I've told my peers this - if i could go back in time i would use stored procedures with a thin API abstracting it away.

我已经告诉过我的同行了 - 如果我能及时回过头来,我会使用带有瘦API的存储过程来抽象它。

Either that or use a "lightweight" ORM like Dapper or Massive.

或者使用像Dapper或Massive这样的“轻量级”ORM。

EF gave me too much bloat, complexity with associations (particularly inheritance model), bug's never fixed, and problems with "updating" entities in a stateless environment such as MVC.

EF给了我太多膨胀,关联的复杂性(特别是继承模型),bug从未修复,以及在无状态环境(如MVC)中“更新”实体的问题。

Don't really care if i get downvoted - just want to put in my two cents. Initially i loved EF, because i came from a L2SQL background so it was an easy transition. But once i started digging under the covers i found out how painful it is to work with.

我真的不在乎我是否会被投票 - 只想投入我的两分钱。最初我喜欢EF,因为我来自L2SQL背景,所以这是一个简单的过渡。但是,一旦我开始挖掘,我发现它是多么痛苦。

That being said - i haven't used NHibernate so i can't comment on that, only commenting on Entity Framework.

话虽如此 - 我还没有使用NHibernate所以我不能对此发表评论,只评论实体框架。

Stick close to the metal - you'll get better performance in the long run. Write code in the "real" model - SQL, use indexes, let SQL Server (or Oracle)'s engine do what it does best.

贴近金属 - 从长远来看,你会获得更好的表现。在“真实”模型中编写代码 - SQL,使用索引,让SQL Server(或Oracle)的引擎做它最擅长的事情。

As consistent and intelligent the LINQ framework is, IMO (and that's all we can do here, give opinions), LINQ-Entities just does not generate good enough SQL when you have a non-basic model (which most people do).

由于LINQ框架是一致且智能的,IMO(这就是我们可以在这里做的,给出意见),当你有一个非基本模型(大多数人都这样做)时,LINQ-Entities就不能产生足够好的SQL。

My EF4 Pet Peeves:

我的EF4 Pet Peeves:

  1. Can't eager load only certain "types". E.g if you have Post and Location as a *..*, and you have Question as a type of Post, there is no way to retrieve a Location and just it's Question's. You must either eager load all Posts, or use an anonymous type projection. In general, eager loading is extremely painful.

    不能只加载某些“类型”。例如,如果您将帖子和位置作为* .. *,并且您将问题作为一种类型的帖子,则无法检索位置而只是问题的问题。您必须先加载所有帖子,或使用匿名类型投影。一般来说,急切加载是非常痛苦的。

  2. Updating relationships on an existing entity, in a stateless, POCO scenario. Again, if you have a Post, which has many Location's, and you want to change the Location an existing Post is linked to, there is no easy way to do so with an MVC controller action. In order for EF to deem a relationship modified when you work with POCO's, you need to actually set it to modified. But if you have POCO's, the relationships are usually ICollection<TPOCO>, so you don't have these built in methods. You end up manually setting the Entity State in the guts of the OSM when you do Save. I ended up manually merging entities in, basically left-to-right.

    在无状态的POCO场景中更新现有实体的关系。同样,如果您有一个Post,它有许多Location,并且您想要更改现有Post链接到的Location,那么使用MVC控制器操作就没有简单的方法。为了让EF在使用POCO时认为修改了关系,您需要将其实际设置为已修改。但是如果你有POCO,那么关系通常是ICollection ,所以你没有这些内置的方法。执行保存时,最终会在OSM的内核中手动设置实体状态。我最终手动合并实体,基本上是从左到右。

  3. No batching of statements. I believe NHibernate supports this. This is big problem with EF, especially if you want to update multiple objects in a single trip. I usually end up using a stored procedure, defeating the point of EF in the first place.

    没有批量陈述。我相信NHibernate支持这一点。这是EF的一个大问题,特别是如果你想在一次旅行中更新多个对象。我通常最终使用存储过程,首先击败了EF点。

  4. Can't map lookup tables to enum's.. Okay, so this isn't a huge issue, but it's an annoying one. Lookup tables are a natural fit for an enum, but EF simply doesn't support it - despite pleas from the community from day 1. No idea why this hasn't been put in.

    无法将查找表映射到枚举..好吧,所以这不是一个大问题,但它是一个令人讨厌的问题。查找表非常适合枚举,但EF根本不支持它 - 尽管社区从第1天开始请求。不知道为什么没有这样做。

#1


4  

EF is very well integrated with .NET and Visual Studio. Gives you a very good designer inside Visual Studio, and leverage LINQ to write queries that are very easy to read.

EF与.NET和Visual Studio非常完美地集成在一起。在Visual Studio中为您提供了一个非常优秀的设计器,并利用LINQ编写非常易于阅读的查询。

For me, this is a no-brainer. I would go with EF4 without a doubt.

对我来说,这是一个明智的选择。毫无疑问,我会选择使用EF4。

#2


1  

If you are doing first time I would recommend you to go with EF because its easy to paly with it no more configuration and hidden properties....no need to apply any extra efforts just add the object and your task is done.

如果你是第一次做我会建议你去EF,因为它很容易与它配合,没有更多的配置和隐藏属性....不需要任何额外的努力只需添加对象,你的任务就完成了。

but if you are looking better performance go for NHibernate.

但如果你看起来更好的表现去NHibernate。

#3


1  

The answer depends on which database you're using on the backend. If you're using any of the Microsoft databases then EF is the way to go.

答案取决于您在后端使用的数据库。如果您使用的是任何Microsoft数据库,那么EF就是您的选择。

Oracle doesn't have a client that supports EF yet (it is coming), so you'll need to use NHibernate to talk to Oracle until they update their client.

Oracle还没有支持EF的客户端(即将推出),所以在更新客户端之前,您需要使用NHibernate与Oracle通信。

#4


0  

I'd go for NHibernate, because it allows you to tweak performance better than EF and is better portable across different databases.

我会选择NHibernate,因为它可以让你比EF更好地调整性能,并且可以在不同的数据库中更好地移植。

When using asp.net mvc for the first time, you can consider using S#arp architecture. It uses NHibernate. On the website it is explained clearly how to get started quickly.

当您第一次使用asp.net mvc时,您可以考虑使用S#arp架构。它使用NHibernate。在网站上,它清楚地解释了如何快速入门。

#5


0  

Neither.

都不是。

I've used EF for the past year and the problems i've had are not worth the hassle.

我过去一年都使用EF,而且我遇到的问题不值得麻烦。

I've told my peers this - if i could go back in time i would use stored procedures with a thin API abstracting it away.

我已经告诉过我的同行了 - 如果我能及时回过头来,我会使用带有瘦API的存储过程来抽象它。

Either that or use a "lightweight" ORM like Dapper or Massive.

或者使用像Dapper或Massive这样的“轻量级”ORM。

EF gave me too much bloat, complexity with associations (particularly inheritance model), bug's never fixed, and problems with "updating" entities in a stateless environment such as MVC.

EF给了我太多膨胀,关联的复杂性(特别是继承模型),bug从未修复,以及在无状态环境(如MVC)中“更新”实体的问题。

Don't really care if i get downvoted - just want to put in my two cents. Initially i loved EF, because i came from a L2SQL background so it was an easy transition. But once i started digging under the covers i found out how painful it is to work with.

我真的不在乎我是否会被投票 - 只想投入我的两分钱。最初我喜欢EF,因为我来自L2SQL背景,所以这是一个简单的过渡。但是,一旦我开始挖掘,我发现它是多么痛苦。

That being said - i haven't used NHibernate so i can't comment on that, only commenting on Entity Framework.

话虽如此 - 我还没有使用NHibernate所以我不能对此发表评论,只评论实体框架。

Stick close to the metal - you'll get better performance in the long run. Write code in the "real" model - SQL, use indexes, let SQL Server (or Oracle)'s engine do what it does best.

贴近金属 - 从长远来看,你会获得更好的表现。在“真实”模型中编写代码 - SQL,使用索引,让SQL Server(或Oracle)的引擎做它最擅长的事情。

As consistent and intelligent the LINQ framework is, IMO (and that's all we can do here, give opinions), LINQ-Entities just does not generate good enough SQL when you have a non-basic model (which most people do).

由于LINQ框架是一致且智能的,IMO(这就是我们可以在这里做的,给出意见),当你有一个非基本模型(大多数人都这样做)时,LINQ-Entities就不能产生足够好的SQL。

My EF4 Pet Peeves:

我的EF4 Pet Peeves:

  1. Can't eager load only certain "types". E.g if you have Post and Location as a *..*, and you have Question as a type of Post, there is no way to retrieve a Location and just it's Question's. You must either eager load all Posts, or use an anonymous type projection. In general, eager loading is extremely painful.

    不能只加载某些“类型”。例如,如果您将帖子和位置作为* .. *,并且您将问题作为一种类型的帖子,则无法检索位置而只是问题的问题。您必须先加载所有帖子,或使用匿名类型投影。一般来说,急切加载是非常痛苦的。

  2. Updating relationships on an existing entity, in a stateless, POCO scenario. Again, if you have a Post, which has many Location's, and you want to change the Location an existing Post is linked to, there is no easy way to do so with an MVC controller action. In order for EF to deem a relationship modified when you work with POCO's, you need to actually set it to modified. But if you have POCO's, the relationships are usually ICollection<TPOCO>, so you don't have these built in methods. You end up manually setting the Entity State in the guts of the OSM when you do Save. I ended up manually merging entities in, basically left-to-right.

    在无状态的POCO场景中更新现有实体的关系。同样,如果您有一个Post,它有许多Location,并且您想要更改现有Post链接到的Location,那么使用MVC控制器操作就没有简单的方法。为了让EF在使用POCO时认为修改了关系,您需要将其实际设置为已修改。但是如果你有POCO,那么关系通常是ICollection ,所以你没有这些内置的方法。执行保存时,最终会在OSM的内核中手动设置实体状态。我最终手动合并实体,基本上是从左到右。

  3. No batching of statements. I believe NHibernate supports this. This is big problem with EF, especially if you want to update multiple objects in a single trip. I usually end up using a stored procedure, defeating the point of EF in the first place.

    没有批量陈述。我相信NHibernate支持这一点。这是EF的一个大问题,特别是如果你想在一次旅行中更新多个对象。我通常最终使用存储过程,首先击败了EF点。

  4. Can't map lookup tables to enum's.. Okay, so this isn't a huge issue, but it's an annoying one. Lookup tables are a natural fit for an enum, but EF simply doesn't support it - despite pleas from the community from day 1. No idea why this hasn't been put in.

    无法将查找表映射到枚举..好吧,所以这不是一个大问题,但它是一个令人讨厌的问题。查找表非常适合枚举,但EF根本不支持它 - 尽管社区从第1天开始请求。不知道为什么没有这样做。