【问题标题】:Subsonic and optimistic concurrency亚音速和乐观并发
【发布时间】:2013-12-27 23:02:32
【问题描述】:

Subsonic 是否以某种方式使用乐观并发?

【问题讨论】:

    标签: subsonic


    【解决方案1】:

    如果使用你的意思是内置到SubSonic,那么不是。然而,使用 SubSonic 可以相当简单地实现乐观并发。

    假设您使用的是 SQL Server(如果不是,我会让您将以下说明转换为适用于您的数据库提供程序的解决方案),这是一种方法:

    1. 在您希望确保并发性的每个表上包含timestamp 类型的列。

      CREATE TABLE Product
      (
          ProductID int NOT NULL IDENTITY(1,1),
          Name varchar(256) NOT NULL,
          RowStamp timestamp  /* This will hold a timestamp for the table */
      )
      
    2. 将时间戳的值与数据一起读取,以便以后使用它进行比较。

      var product = new SubSonic.Select()
          .From<Product>()
          .Where(Product.ProductIDColumn).IsEqualTo(productId)
          .ExecuteSingle<Product>();
      var rowStamp = product.RowStamp;
      
      // ...  Show a form to the user with the data from the product      
      
    3. 在执行UPDATE 时,将时间戳的值与数据库值进行比较。如果时间戳不匹配,则该行已被修改,并且可以将情况通知用户(或者您可以随意处理)

      // ... After retrieving the values from the form
      
      var result = new SubSonic.Update(Product.TableSchema)
          .Set(Product.NameColumn).Equal(newName)
          .Where(Product.ProductIDColumn).IsEqualTo(productId)
          .And(Product.RowStamp).IsEqualTo(rowStamp)
          .Execute();
      
      if (result != 1)
      {
          // Notify the user there may be a problem
      }
      

    【讨论】:

    • 这似乎没问题。必须自己实现所有逻辑或创建通用方式。是否有某种我可以学习的手动文档 api 等?我的搜索没有任何结果。谢谢非常麝香
    【解决方案2】:

    我在这里找到了一个我目前正在测试的解决方案。

    http://sites.google.com/site/subsonicoptimistic/home

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      相关资源
      最近更新 更多