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

EF 6 Code-First系列文章目录:

在EF 6和EF Core中,ConcurrencyCheck可以应用于实体的一个或者多个属性上面。当属性被标识了这个特性,在生成的数据表中的相应的列,就会用来做乐观检查.

using System.ComponentModel.DataAnnotations;

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

在上面的例子中,ConcurrencyCheck特性应用在Student实体的StudentName属性上,所以EF将会在更新的时候,包含StudentName列,用于乐观检查,看看下面的例子:

using(var context = new SchoolContext())
{
var std = new Student()
{
StudentName = "Bill"
}; context.Students.Add(std);
context.SaveChanges(); std.StudentName = "Steve";
context.SaveChanges();
}

上面的代码例子,将会在更新的时候,生成这样的语句【Where条件中】:

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特性只能用在单独的byte数组属性上,而ConcurrencyCheck特性可以用在任何数据类型的的任何数量的属性上面。

9.12 翻译系列:数据注解特性之ConcurrencyCheck【EF 6 Code-First系列】的更多相关文章

  1. 7.3 数据注解特性之ConcurrencyCheck特性【Code-First系列】

    ConcurrencyCheck特性可以应用到领域类的属性中.当EF执行更新操作的时候,Code-First将列的值放在where条件语句中,你可以使用这个CurrencyCheck特性,使用已经存在 ...

  2. 9.10 翻译系列:EF数据注解特性之StringLength【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/stringlength-dataannotations-attribute-in-co ...

  3. 9.9 翻译系列:数据注解特性之--MaxLength 【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribut ...

  4. 9.7 翻译系列:EF数据注解特性之--InverseProperty【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in ...

  5. 9.3 翻译系列:数据注解特性之Key【EF 6 Code-First 系列】

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

  6. 9.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】

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

  7. 9.翻译系列:EF 6以及EF Core中的数据注解特性(EF 6 Code-First系列)

    原文地址:http://www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx EF 6 Code-F ...

  8. 9.1 翻译系列:数据注解特性之----Table【EF 6 Code-First 系列】

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

  9. 9.5 翻译系列:数据注解之ForeignKey特性【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code ...

随机推荐

  1. Mistwald POJ

    一开始看不出来是快速幂矩阵的题目 先要把整个地图离散化为1,2,3,4,.... 连成一个有向图 邻接矩阵的平方意为:假如a->b  且b->c     那么一次平方后   a->c ...

  2. 009 搭建Spark的maven本地windows开发环境以及测试

    在看完下面的细节之后,就会发现,spark的开发,只需要hdfs加上带有scala的IDEA环境即可.  当run运行程序时,很快就可以运行结束. 为了可以看4040界面,需要将程序加上暂定程序,然后 ...

  3. 032 HDFS中高可用性HA的讲解

    HDFS Using QJM HA使用的是分布式的日志管理方式 一:概述 1.背景 如果namenode出现问题,整个HDFS集群将不能使用. 是不是可以有两个namenode呢 一个为对外服务-&g ...

  4. 关于 C++ STL

    一.STL简介 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov.Meng Lee和David R ...

  5. Bmob后端云使用步骤

    1.登录创建应用后得到id 2.在清单文件中添加权限 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion ...

  6. IdentityServer4-前后端分离的授权验证(六)

    上两节介绍完Hybrid模式在MVC下的使用,包括验证从数据获取的User和Claim对MVC的身份授权.本节将介绍Implicit模式在JavaScript应用程序中的使用,使用Node.js+Ex ...

  7. curl解压gzip页面gzcompress内容

    $headers = array( //"Content-type:application/json;charset='utf-8'", "Cache-Control:n ...

  8. ssm数据库中文乱码问题

    (1)详解Spring中的CharacterEncodingFilter--forceEncoding为true    <a href="http://www.cnblogs.com/ ...

  9. 第一次打开app

    //判断是不是第一次启动应用 if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) { ...

  10. 如何对MongoDB 3.2.7进行用户权限管理配置

    转自:https://www.jianshu.com/p/a4e94bb8a052 上次写了一篇在CentOS7上源码安装MongoDB 3.2.7,完成了MongoDB 3.2.7的安装,但需要应用 ...