开发者

Fluent NHibernate: Lock row in a multiple user environment

开发者 https://www.devze.com 2023-04-10 17:32 出处:网络
Lets assume this hierarchy. public class A { public int Id { get; set; } public IEnumerable<B> Children { get; set; }

Lets assume this hierarchy.

public class A
{
  public int Id { get; set; }
  public IEnumerable<B> Children { get; set; }
}

public class B
{
  public A Parent { get; set; }
  public string Name { get; set; }
}

I've created a app in WinForms and for database communication I use Fluent NHibernate. Multiple users can use the app simultaneously, however when a user decides to work with a specific instance of A (or a specific row in the database), I want to make that row non-ac开发者_运维问答cesible for other users. And when the user is finished working with that specific row, I want to make it accesible again. Can this be accomplished?

The idea is that a user fetches A and then works with some or all of its Children (List of B). At that stage, A is locked so that no other user can work with the children of A. When the user is finished working A is released and accesible to other users.


Fluent NHibernate is about your mapping. There are several ways to do data access with NHibernate. You do not specify which you use, but either way, the same principles apply.

What you describe is pessimistic locking. The way to do it in NHibernate is described here. I think you'd want to use LockMode.UPGRADE_NOWAIT.

If B-s can only be accessed through A it would indeed be sufficient to lock A.

0

精彩评论

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

关注公众号