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.
精彩评论