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. 【leetnode刷题笔记】Maximum Depth of binary tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  2. [算法]K-SUM problem

    一.Two Sum Given an array of integers, find two numbers such that they add up to a specific target nu ...

  3. HTML特效文字代码大全

     HTML特效文字代码大全一.从右向左移代码<marquee direction=left>需要移动的文字</marquee>二.从左向右移代码<marquee dire ...

  4. MapReduce分区的使用(Partition)

    MapReduce中的分区默认是哈希分区,根据map输出key的哈希值做模运算,如下 int result = key.hashCode()%numReduceTask; 如果我们需要根据业务需求来将 ...

  5. Java -- 国际化 多语化

    1. 以中英两种语言做示例,显示 "hello" 2. 建立英文语言文件 "mess_en_US.properties ", 输入内容 "hello= ...

  6. Delphi中TList类应用

    在DELPHI中指针最常见的就是和类TLIST结合起来使用.下面是一个很简单的例子,希望对这个例子的分析能让大家对使用TLIST类有一个简单的认识. 代码的功能是使用指针和Tlist来生成一个牌串,并 ...

  7. 分享知识-快乐自己:关于 String 小案例

    单个字符出现的次数: /*** * 验证是否符合拆分条件 * * @param text * 原字符串 * @param sub * 判断条件 * @return */ public static i ...

  8. Firefox 不知道如何打开此地址,因为协议 (javascrpit) 未和任何程序关联.

    用火狐打开出现这个错误,360没事:这个是什么原因???怎么解决?代码:<a href="javascrpit:;"onclick="showD('pas','ri ...

  9. PHP获取指定日期是星期几的实现方法

    这篇文章主要介绍了PHP获取指定日期是星期几的实现方法,涉及php针对日期的读取.判断与字符串.数组相关运算操作技巧,需要的朋友可以参考下 本文实例讲述了PHP获取指定日期是星期几的实现方法.分享给大 ...

  10. BEC listen and translation exercise 36

    你所持的护照可使你享有免费医疗.Your passport qualifies you to receive free medical treatment.公司指使其职员挖对手的客户.The comp ...