ConcurrencyCheck特性可以应用到领域类的属性中。当EF执行更新操作的时候,Code-First将列的值放在where条件语句中,你可以使用这个CurrencyCheck特性,使用已经存在的列做并发检查,而不是使用单独的TimeStamp列来做并发检查。 看下面的代码: 然后,我们来修改下main函数的测试代码:
然后错误并发消息是:
exec sp_executesql N'UPDATE [dbo].[StudentInfo]
SET [StudentName] = @0, [StdId] = @1
WHERE ((([StudentKey1] = @2) AND ([StudentKey2] = @3)) AND ([StudentName] = @4))
',N'@0 nvarchar(20),@1 int,@2 int,@3 int,@4 nvarchar(20)',@0=N'Test Only For one',@1=1,@2=1,@3=1,@4=N'Test Only For one' 请注意:
Note that TimeStamp attribute can only be applied to a single byte array property in a class, whereas ConcurrencyCheck attribute can be applied to any number of properties with any datatype.
TimeStamp特性只能够被用到单字节属性的类中,但是ConcurrencyCheck特性可以被用到任何数量,任何类型的属性中。
|