开发者

A nhibernate session problem about transactions

开发者 https://www.devze.com 2023-03-12 21:17 出处:网络
I will try to explain in pseudo code. There\'re two sessions s1 and s2 int totalEntity = 0; Thread1 { s1.BeginTransaction ();

I will try to explain in pseudo code.

There're two sessions s1 and s2

int totalEntity = 0;

Thread1
{
s1.BeginTransaction ();
loop (infinite)
{
   totalEntity = s1.List<Entity> ().Count ();
}
s1.EndTransaction ();
}


s2.BeginTransaction ();
s2.Insert<Entity> ();
s2.EndTransaction ();

When i run the s2, the totalEntity still is zero becaus开发者_运维百科e the s1.Transaction not commited. How can i get the real totalEntity as 1, in the loop?


You can call flush, it'll cause the db to be updated.


I think it's better if the transaction is inside the loop.

0

精彩评论

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