我正在考虑使用POCO而不是自动生成实体,因为我不想对框架有任何依赖
我想知道这是否会影响性能,我不确定在运行时动态代理我的实体是否会影响性能。
另外,我想知道如果让EF4为我生成模型会不会更快。
在我目前的项目中,我非常关心性能,我读过很多次关于L2S比EF2略快的文章,但我对EF4不太确定,所以现在我想知道使用EF4而不是Linq2SQL会不会有性能问题。
我真的很想使用POCO;这就是为什么我更喜欢EF4,但我也不想有性能问题。
EF4和Ling2SQL是我唯一的选择,因为我不能使用原生ADO.net或任何其他对象关系管理,所以你能从性能的角度分享你对EF4和Linq2SQL的经验吗?
提前谢谢。
发布于 2011-06-16 21:24:46
最近,ADO.NET团队发布了支持代码优先开发的EF Power Tools,它可以从你的模型/数据库(仅限ADO.NET)自动生成POCOs,并且可以将POCOs与其他元类完全分离,以提供数据库表的结构信息。
在ADO.NET团队博客中,using EF Proxies被提到如下
When creating instances of POCO entity types, the Entity Framework often creates instances of a dynamically generated derived type that acts as a proxy for the entity. This proxy overrides some virtual properties of the entity to insert hooks for performing actions automatically when the property is accessed.
Sometimes disabling proxy creation is useful to prevent the Entity Framework from creating proxy instances. For example, serializing non-proxy instances is considerably easier than serializing proxy instances. Proxy creation can be turned off by clearing the ProxyCreationEnabled flag.
当然,创建代理不会有很好的性能,但如上所述,它只是覆盖了一些虚拟属性来加载相对属性,所以我认为创建代理对象而不是POCOs不是问题。
发布于 2011-06-20 23:06:08
如果你真的很关心性能,可以看看Dapper.NET,他们主页的这个section对各种OR框架进行了相当不错的比较,包括LINQ to SQL和Entity Framework。
一般来说,POCO是你最快的选择。Dapper会帮你的。
仅供参考: StackOverflow是由StackOverflow使用的,Dapper产生的流量令人惊叹。
发布于 2011-06-16 20:55:19
首先,我没有注意到POCO和模型/数据库在性能方面的巨大差异。我注意到EF比Linq2Sql、Massive、PetaPoco、Ado.Net甚至nHibernate都要慢。
https://stackoverflow.com/questions/6372132
复制相似问题