Which atomic and what not
, SQL Server . NHibernate ( O/RM), , select , , update . not . , , . , , , , .
, - , . , , :
public class BodyOfWater
{
public virtual int Id { get; set; }
public virtual StateOfMatter State { get; set; }
public virtual void Freeze()
{
if (State != StateOfMatter.Liquid)
throw new InvalidOperationException("You cannot freeze a " + State + "!");
State = StateOfMatter.Solid;
}
public virtual void Boil()
{
if (State != StateOfMatter.Liquid)
throw new InvalidOperationException("You cannot boil a " + State + "!");
State = StateOfMatter.Gas;
}
}
, :
new BodyOfWater
{
Id = 1,
State = StateOfMatter.Liquid
};
, . A :
using (var transaction = sessionA.BeginTransaction())
{
var water = sessionA.Get<BodyOfWater>(1);
water.Freeze();
sessionA.Update(water);
transaction.Commit();
}
B ( !)...
using (var transaction = sessionB.BeginTransaction())
{
var water = sessionB.Get<BodyOfWater>(1);
water.Boil();
sessionB.Update(water);
transaction.Commit();
}
... !!! ? . , : " Solid!"? B , A , , -, , .
, Version NHibernate <version />:
public virtual int Version { get; set; }
, NHibernate , , , , . concurrency -naive sql, ...
update BodyOfWater set State = 'Gas' where Id = 1;
... NHibernate :
update BodyOfWater set State = 'Gas', Version = 2 where Id = 1 and Version = 1;
, , 0, NHibernate , - - - , , - , . NHibernate a StaleObjectStateException.
-
select update, concurrency. "" -. , HTML- . . , , - , , .
, , , , . , , , , , select update, , , "" . "", , , , .