原文:http://www.entityframeworktutorial.net/code-first/concurrencycheck-dataannotations-attribute-in-code-first.aspx

ConcurrencyCheck属性可以应用于域类的属性。 当EF执行表的update命令时,Code First会在“where”子句中使用列的值。 当你想要使用现有列进行并发检查时,可以使用ConcurrencyCheck属性,而不是用并发的单独时间戳列。

请看以下示例:

using System.ComponentModel.DataAnnotations;

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

如上例所示,ConcurrencyCheck属性应用于Student类的现有StudentName属性。

因此,Code-First将在update命令中包含StudentName列,以检查乐观并发。

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

注意,TimeStamp属性只能应用于类中的单字节数组属性,而ConcurrencyCheck属性可以应用于具有任何数据类型的任意数量的属性。

有关乐观锁和悲观锁、示例等请参考园友文章:http://www.cnblogs.com/Gyoung/archive/2013/01/18/2866649.html

【译】第12节---数据注解-ConcurrencyCheck的更多相关文章

  1. 【译】第20节---数据注解-InverseProperty

    原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...

  2. 【译】第19节---数据注解-NotMapped

    原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...

  3. 【译】第18节---数据注解-ForeignKey

    原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...

  4. 【译】第17节---数据注解-Column

    原文:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first. ...

  5. 【译】第16节---数据注解-Table

    原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...

  6. 【译】第15节---数据注解-StringLength

    原文:http://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-code- ...

  7. 【译】第14节---数据注解-MaxLength/MinLength

    原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...

  8. 【译】第13节---数据注解-Required

    原文:http://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-firs ...

  9. 【译】第11节---数据注解-TimeStamp

    原文:http://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code-fir ...

随机推荐

  1. Presto 学习参考资料

    Presto 文档资料: 0.1版:Presto 0.100 Documentation 0.213版:Presto 0.213 Documentation 阿里云 presto 学习资料:https ...

  2. php获得可靠的精准的当前时间 ( 通过授时服务器 )

    有一种情形是这样子的,比如机票业务中的订票流程,我们需要一个非常可靠的当前时间来支持,尽管大多数服务器的时间是非常准确的,我们使用time()来获取的时间是可靠的,但未免会有不确切的情况,也有的服务器 ...

  3. Matlab基础部分2-数组和矩阵分析

    矩阵块操作: 矩阵尺寸改变: 矩阵的查找: 矩阵的排序: 矩阵求和: 矩阵的求积: 矩阵的差分: 全零矩阵: 单位矩阵: 随机矩阵: 伴随矩阵: 方针行列式计算: 特征值: 对角矩阵: 三角矩阵: 矩 ...

  4. 75.Java异常处理机制-手动抛出异常

    package testDate; import java.io.File; import java.io.FileNotFoundException; public class TestReadFi ...

  5. 直播协议的选择:RTMP vs. HLS

    文章转自:直播协议的选择:RTMP vs. HLS 前言 随着直播业务的兴起,越来越多的直播平台开始涌现,这火热的程度好像一个应用不带上直播业务出来都不好意思跟人打招呼.想要做一个直播业务,主要包括三 ...

  6. Django框架----命名URL和URL反向解析

    在使用Django 项目时,一个常见的需求是获得URL 的最终形式,以用于嵌入到生成的内容中(视图中和显示给用户的URL等)或者用于处理服务器端的导航(重定向等).人们强烈希望不要硬编码这些URL(费 ...

  7. Golang面向对象_继承

    package main import "fmt" type Person struct { name string //名字 sex byte //性别 age int //年龄 ...

  8. [VS] - "包含了重复的“Content”项。.NET SDK 默认情况下包括你项目中的“Content”项。

    copy to :http://www.cnblogs.com/jinzesudawei/p/7376916.html VS 2017 升级至  VS 2017 v15.3 后,.Net Core 1 ...

  9. Getting started with Kaggle -- Kaggle Competitions

    1: The Competition We'll be learning how to generate a submission for a Kaggle competition. Kaggle i ...

  10. mysql 水平分表技术

    这里做的是我的一个笔记. 水平分表比较简单, 理解就是: 合并的表使用的必须是MyISAM引擎 表的结构必须一致,包括索引.字段类型.引擎和字符集 数据表 user1 CREATE TABLE `us ...