开发者

How to Queue The Add Operation in NHibernate?

开发者 https://www.devze.com 2023-01-20 12:34 出处:网络
Is there some way to queue the \"Add\" operation in NHibernate, just like Linq to SQL and Entity Framework does?

Is there some way to queue the "Add" operation in NHibernate, just like Linq to SQL and Entity Framework does?

I want to add an entity to the repository, but I don't want to save it to the database immediately, because the business logic is complex. I want to submit all changes when I call ITransaction.Commit(), just like Entity Framework does. Can I do that?

NOTE: I found that NHibernate will execute an insert command as soon as I call ISession.Save() method, that's not expected.

UPDATE: I try setting the FlushMode to Commit. But it still save the entity immediately, not commit all changes when I call ITransaction.Commit().

UPDATE 2 I found the reason here http://nhibernate.info/doc/nh/en/index.html#manipulatingdata-flushing : (An exception is that objects using native ID generation are inserted when they are saved.). So I can only change the Id generator to some thing other than "identity"? No oth开发者_Python百科er solutions similar to the solution in EntityFramework?


Use session.BeginTransaction() and read about transactions.


That's how identity works; session.Save returns the POID and the only way to get it when using identity is performing the actual insert.

More about that here: http://fabiomaulo.blogspot.com/2009/02/nh210-generators-behavior-explained.html

0

精彩评论

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

关注公众号