ConcurrencyCheck Attribute:

ConcurrencyCheck attribute can be applied to a property of a domain class. Code First takes the value of a column in "where" clause when EF executes update command for the table. You can use ConcurrencyCheck attribute when you want to use existing column for concurrency check and not a separate timestamp column for concurrency.

Consider the following example.

using System.ComponentModel.DataAnnotations;

public class Student
{
public Student()
{ } public int StudentId { get; set; } [ConcurrencyCheck]
public string StudentName { get; set; }
}

As you can see in the above example, ConcurrencyCheck attribute is applied to existing StudentName property of the Student class. So, Code-First will include StudentName column in update command to check for optimistic concurrency.

exec sp_executesql N'UPDATE [dbo].[Students]
SET [StudentName] = @0
WHERE (([StudentId] = @1) AND ([StudentName] = @2))
',N'@0 nvarchar(max) ,@1 int,@2 nvarchar(max) ',@0=N'Steve',@1=1,@2=N'Bill'
go

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.

Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute的更多相关文章

  1. Entity Framework Code-First(9.6):DataAnnotations - StringLength Attribute

    DataAnnotations - StringLength Attribute: StringLength attribute can be applied to a string type pro ...

  2. Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute

    DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...

  3. Entity Framework Code-First(9.10):DataAnnotations - NotMapped Attribute

    DataAnnotations - NotMapped Attribute: NotMapped attribute can be applied to properties of a class. ...

  4. Entity Framework Code-First(9.9):DataAnnotations - ForeignKey Attribute

    DataAnnotations - ForeignKey Attribute: ForeignKey attribute can be applied to properties of a class ...

  5. Entity Framework Code-First(9.8):DataAnnotations - Column Attribute

    DataAnnotations - Column Attribute: Column attribute can be applied to properties of a class. Defaul ...

  6. Entity Framework Code-First(9.7):DataAnnotations - Table Attribute

    DataAnnotations - Table Attribute: Table attribute can be applied to a class. Default Code-First con ...

  7. Entity Framework Code-First(9.2):DataAnnotations - TimeStamp Attribute

    DataAnnotations - TimeStamp Attribute: TimeStamp attribute can be applied to only one byte array pro ...

  8. Entity Framework Code-First(9.1):DataAnnotations - Key Attribute

    DataAnnotations - Key Attribute: Key attribute can be applied to properties of a class. Default Code ...

  9. Entity Framework Code-First(9.4):DataAnnotations - Required Attribute

    Required attribute can be applied to a property of a domain class. EF Code-First will create a NOT N ...

随机推荐

  1. python3 函数 二

    1.函数嵌套 1.1函数嵌套定义 :在一个函数的内部,又定义另外一个函数. def f1():     x=1     def f2():         print('from f2')     f ...

  2. P4455 [CQOI2018]社交网络(矩阵树定理)

    题目 P4455 [CQOI2018]社交网络 \(CQOI\)的题都这么裸的吗?? 做法 有向图,指向叶子方向 \(D^{out}(G)-A(G)\) 至于证明嘛,反正也就四个定理,先挖个坑,省选后 ...

  3. CHAR,TCHAR,WCHAR 三者的区别与转换

    #ifdef   UNICODE               typedef   wchar_t   TCHAR; #else               typedef   unsigned   c ...

  4. ios 微信发送位置

    @interface GroupReportViewController () <BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCode ...

  5. TCP和UDP?

    简单讲,TCP是打电话,UDP是发短信.

  6. 命令行执行大sql文件

    mysql -h localhost -u root -p 123456 < F:/hello world/niuzi.sql

  7. kylin_学习_01_kylin安装部署

    一.环境准备 根据官方文档,kylin是需要运行在hadoop环境下的,如下图: 1.hadoop环境搭建 参考:hadoop_学习_02_Hadoop环境搭建(单机) 2.hbase环境搭建 参考: ...

  8. Linux_笔记_01_设置静态IP与 SecureCRT连接Linux

    步骤一至三,即可设置好静态IP 步骤四至九,使SecureCRT连接Linux 步骤一:编辑ifcfg-eth0 文件 1.打开ifcfg-eth0 文件 使用命令:vi /etc/sysconfig ...

  9. bzoj1002轮状病毒

    高精度练习题 根据什么什么基尔霍夫矩阵 反正就是高精度练习 #include<iostream> #include<cstdio> using namespace std; s ...

  10. [转]django 日志logging的配置以及处理

    http://davidbj.blog.51cto.com/4159484/1433741 日志在程序开发中是少不了的,通过日志我们可以分析到错误在什么地方,有什么异常.在生产环境下有很大的用途.在J ...