2009-10-01 53 views

回答

3

如果按使用您的意思是内置 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 
    } 
    
+1

很好的答案。工作很好。 – 2009-10-02 05:30:34

+0

这似乎确定。必须自己实现所有的逻辑或者创建一个通用的方式。有什么我可以学习的手动文档api等?我的搜索没有任何结果。 Thx very musch – Mantzas 2009-10-02 17:42:04

+0

请查阅官方文档http://subsonicproject.com/docs/ – dcharles 2009-10-03 06:22:58