【发布时间】:2012-07-10 12:40:23
【问题描述】:
我理解并接受身份生成器会破坏工作单元,因为它需要在事务实际提交时先进行插入,如http://fabiomaulo.blogspot.com/2008/12/identity-never-ending-story.html 中所述。我知道替代方案以及为什么它们更好(就手头的问题而言,以及总体而言)。
我的问题是为什么该实现存在,以及这些问题是否会影响 EF(纯粹是好奇)。我见过的唯一真正的理由是:"NHibernate needs the identity because every entity in the session (they are called "persistent entities") needs to be identified. The identity is also normally used to determine if the record already exists in the database (unsaved value)."
为什么它必须立即具有价值呢?为什么它不能推迟 INSERT 直到提交发生,提交,检索值,并根据返回的身份更新实体,然后插入/更新/不管它们?
不太重要的问题:EF 是否遇到同样的问题?我知道 ISession 是一个合适的 UoW 实现; EF 没有实现 UoW 模式,还是有不同的方法来处理这个问题,如果有,是什么?
【问题讨论】:
标签: entity-framework nhibernate