NHibernate Transactions on Reads

后端 未结 5 958
清酒与你
清酒与你 2020-12-14 01:34

I have read the documentation and explanation on why it is highly recommended to use transactions on read operations in NH. However, I still haven\'t totally \"bought\" into

5条回答
  •  既然无缘
    2020-12-14 01:50

    var fooIdFromDb = ExecuteQuery("Select Id from Foo where something = somethingelse");
    var barsFromDb = ExecuteQuery("Select * from Bar where FooId = " + fooIdFromDB);
    

    What if some other transaction deletes rows from Bar between the two queries? You will have issues with phantom data. This is not an NHibernate specific issue. You will have the same problem with any other kind of database access without using transactions. You should read the manual about transactions in general instead of the NHiberante manual.

提交回复
热议问题