【译】第12节---数据注解-ConcurrencyCheck
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的更多相关文章
- 【译】第20节---数据注解-InverseProperty
原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...
- 【译】第19节---数据注解-NotMapped
原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...
- 【译】第18节---数据注解-ForeignKey
原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...
- 【译】第17节---数据注解-Column
原文:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first. ...
- 【译】第16节---数据注解-Table
原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...
- 【译】第15节---数据注解-StringLength
原文:http://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-code- ...
- 【译】第14节---数据注解-MaxLength/MinLength
原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...
- 【译】第13节---数据注解-Required
原文:http://www.entityframeworktutorial.net/code-first/required-attribute-dataannotations-in-code-firs ...
- 【译】第11节---数据注解-TimeStamp
原文:http://www.entityframeworktutorial.net/code-first/TimeStamp-dataannotations-attribute-in-code-fir ...
随机推荐
- BIOS 搭配 MBR/GPT 的开机流程
鸟哥私房菜书上内容: BIOS 搭配 MBR/GPT 的开机流程 在计算机概论里面我们有谈到那个可爱的BIOS与CMOS两个东西, CMOS是记录各项硬件参数且嵌入在主板上面的储存器,BIOS则是一个 ...
- 在Eclipse下配置算法(第四版)运行环境
第一步:配置Eclipse运行环境 Eclipse运行环境配置过程是很简单的,用过Eclipse进行java开发或学习的同学应该都很熟悉这个过程了. 配置过程: (1)系统环境:Windows7 64 ...
- linux mysql主从复制
centos7 安装 mariadb 1 yum 源 -- 配置阿里的 2 rmp 方式 3 源码编译方式 -- 专业DBA 一些知识点: 虚拟环境 不影响 redis/ mariadb/mysq ...
- Step6:SQL Server 数据变更时间戳(timestamp)在复制中的运用
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 方案(Solution) 方案一(Solution One) 方案二(Solution Two ...
- Different between MB SD Connect Compact 5 and MB SD C4 Star Diagnostic Tool
MB SD C4 Star Diagnostic Tool is the professional MB Star Diagnostic Tools for benz cars and trucks. ...
- MyEclipse非正常关闭问题
问题:电脑突然断电,myeclipse非正常关闭,“Package Explorer”非正常显示,出现错误“Could not create the view: An unexpected excep ...
- linux 搭建svn(待完成)
http://blog.csdn.net/lazy_cc/article/details/8726500搭建仓库 http://blog.csdn.net/xocoder/article/detail ...
- CentOS ping: unknown host 解决方法
如果ping命令返回如下错误,那主要的可能性就是系统的DNS设置有误 [root@CentOS5 ~]# ping www.sina.com.cn ping: unknown host www.sin ...
- oracle 11g亿级复杂SQL优化一例(数量级性能提升)
自从16年之后,因为工作原因,项目中就没有再使用oracle了,最近最近支持一个项目,又要开始负责这块事情了.最近在跑性能测试,配置全部调好之后,不少sql还存在性能低下的问题,主要涉及执行计划的不合 ...
- lasticsearch -2.3.x head插件安装(windows系统)
1.进入命令行: home键+R 命令: > cd \elasticsearch根目录\bin\ > plugin install mobz/elasticsearch-head 2. ...