通过在实体框架4.0中使用T4模板创建POCO,松散的是什么?为什么使用实体框架4.0 不创建POCO时的默认行为?
What does one loose by creating POCO using T4 templates in entity framework 4.0? Why is the default behavior when using entity framework 4.0 not to create POCO?
推荐答案事情数量纯POCO在ORM中的使用有限,因为它不会进行更改跟踪。换句话说,当您更改对象并将更改保存到上下文时,您希望将更改的属性保存到数据库。使用纯POCO,您可以使用基于快照的更改跟踪来执行此操作,这是相当低效的。您还可以使用运行时代理来执行此操作,这迫使您将跟踪属性 public virtual ,因此您可以说没有POCO。此外,使用代理意味着您不知道实例的真实运行时类型。
You lose a number of things. A "pure" POCO is of limited use in an ORM, because it will not do change tracking. In other words, when you mutate the object and then save changes to the context, you would like the changed properties saved to the database. With a "pure" POCO you can do this with snapshot based change tracking, which is fairly inefficient. You can also do it with runtime proxies, which force you to make your track properties public virtual, so you arguably don't have a "POCO" anymore. Also, using proxies means that you don't know the true runtime type of the instance.
您还会丢失一些方便属性,如 EntityState 。
You also lose some of the convenience properties like EntityState.
纯POCO不能做延迟加载。再次,你可以使用代理类型解决这个问题,但是,再次,如果你使用代理,你真的没有一个纯粹的POCO。
"Pure" POCOs cannot do lazy loading. Again, you can work around this with proxy types, but, again, if you're using proxies, you don't really have a "pure" POCO.
On其中最重要的是,实体框架中使用POCO实体的需求少于其他一些ORM。这是因为您可以随时使用LINQ将实体类型投影到POCO实例上,而不必首先实现实体实例。所以实体POCO始终在实体框架应用程序中使用,即使您不会以这种方式映射您的实体。
On top of all of this, there is less need to use POCO entities in the Entity Framework than in some other ORMs. This is because you can always project your entity types onto POCO instances using LINQ, without having to materialize the entity instances first. So "pure" POCOs are always available in an Entity Framework application, even if you don't happen to map your entities that way.
更多推荐
实体框架POCO
发布评论