简体   繁体   English

NHibernate 如何跟踪对我的实体中的字段所做的更改?

[英]How NHibernate track changes made to the fields in my entity?

How NHibernate track changes made to the fields in my entity? NHibernate 如何跟踪对我的实体中的字段所做的更改? If I use second level cache and I change my entity, How does it apply my changes to db?如果我使用二级缓存并更改了我的实体,它如何将我的更改应用到数据库?

When you change an entity, the entity becomes "dirty" and nhibernate knows the update the entity in your database when the session is flushed.当您更改实体时,该实体将变为“脏”,并且 nhibernate 知道在刷新 session 时更新数据库中的实体。 That said, sometimes its possible for entities to get marked dirty even though you have made no change.也就是说,有时即使您没有进行任何更改,实体也可能被标记为脏。 This results in unnecessary update calls to your database.这会导致对您的数据库进行不必要的更新调用。

It is best to isolate your entities from your views via view models.最好通过视图模型将实体与视图隔离开来。 Once you pull an entity out of the database, convert it to a view model that you can mangle up.从数据库中拉出实体后,将其转换为视图 model,您可以将其拆分。

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

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