开发者

NHibernate IPreUpdateEventListener weird behaviour

开发者 https://www.devze.com 2022-12-28 11:31 出处:网络
I am using NHibernate 2.0.1 and IPreUpdateEventListener,IPreInsertEventListener events for audit logging purposes.

I am using NHibernate 2.0.1 and IPreUpdateEventListener,IPreInsertEventListener events for audit logging purposes.

I have a basic entity that has a one to many relation like this.

User------->Books

From an ASP.NET MVC controller method i am adding a book to a user like this.

Book book =new Book("LOTR");
var userBook=user.AddBook(book);

After session flushing OnPreInsert event called once for newly created Book object than OnPreUpdate called for all books objects in 开发者_如何学JAVAuser's books collection even they have not changed.So I am updating LastMofiedDate property of all books objects and I dont want to do this. Is this supposed behaviour of NHibernate or am I missing something?


Finally I have solved the problem. The problem was about Enum field on my Book object that mapped as DataType Int32 in mapping file. So NHibernate marks every Book object as dirty after initializition. Further information can be found in this answer

0

精彩评论

暂无评论...
验证码 换一张
取 消