NHibernate and self tracking entities
Is there any architectural or philosophical reason why NHi开发者_Go百科bernate does not have support for self tracking entities? Change tracking based on session is great but it is not usable in some rare cases (e.g. large number of entities in the session but only one entity is modified per transaction).
What is your opinion? Thanks.
You may also take a look to the FindDirty
method of IInterceptor
. Here you can inject you own dirty tracking mechanism, without influence to the business logic and without giving up any other NH feature.
I don't really know what "self-tracking entities" means, I guess it comes from entity framework? The IStatelessSession
does not cache entities. The session is not build to have a lot of entities in the cache, but to only contain the entities to show on the screen to the user. If you need batching, or long running transactions, other tools will do the job better than NHiberante. I guess it is not build in NHiberante for the following reasons:
- People already use other tools.
- There is not much existing code and there are not much existing features to build it.
- Existing features need breaking changes or have to be sacrificed.
- Somebody has to write the code...
There is a crucial difference between NHibernate and the Entity-Framework. The method ObjectContext.SaveChanges(..) of the EF saves only the changes made to the entity while it has been a part of the object context. Example:
MyEntity e = new MyEntity();
e.Key = blabla;
e.Id = 3242342;
e.Name = "Hugo";
using(MyObjectContext ct = new MyObjectcontext())
{
ct.MyEntity.Attach(e);
ct.SaveChanges();
}
This won't change the db at all because no changes where made to the entity while it was part of the context. In NHibernate, the value Hugo would be saved to the db. There is no need for self tracking entities in Nhibernate.
精彩评论