EF代码优先-IsConcurrencyToken() [英] EF Code First - IsConcurrencyToken()

查看:416
本文介绍了EF代码优先-IsConcurrencyToken()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说简单但又神秘:为什么要 StringPropertyConfiguration (以及所有其他PropertyConfiguration)类对 IsConcurrencyToken()

Simple, but yet mysterious for me: Why do StringPropertyConfiguration (and all the other PropertyConfiguration) class(es) have 2 overloads for IsConcurrencyToken()?

第一个:

public StringPropertyConfiguration IsConcurrencyToken()


将属性配置为将乐观并发令牌用作

Configures the property to be used as an optimistic concurrency token.

第二个:

public StringPropertyConfiguration IsConcurrencyToken(bool?)


配置是否将属性
用作乐观的
并发令牌。

Configures whether or not the property is to be used as an optimistic concurrency token.

为什么要在另一个上使用一个?如我所见,这两个重载之间完全没有区别(与它们一起使用时至少没有)...

Why would you use one over the other? As I see it, there's no difference at all between those two overloads (atleast not when working with them)...

通过使用第一个,您将编写如下内容:

By using the first you would write something like:

modelBuilder.Entity<Author>()
    .Property(x => x.Name)
    .IsConcurrencyToken();

通过使用第二个,您将写:

And by using the second you would write:

modelBuilder.Entity<Author>()
    .Property(x => x.Name)
    .IsConcurrencyToken(true/false/null);

我错过了什么吗?

推荐答案

我的意见...

IsConcurrencyToken()默认为true提供一个简单,流畅的方式来定义实体。

The IsConcurrencyToken() defaults to true to provide a simple, fluent manner to define the entity.

IsConcurrencyToken(bool?)允许作者明确地设置实体的 ConcurrencyMode 。这对于高级方案很有用:

The IsConcurrencyToken(bool?) allows the author to definitively set the ConcurrencyMode of the entity. This is useful for advanced scenarios:


  • 覆盖 [ConcurrencyCheck] 属性POCO

  • 允许基于某些自定义约定启用/禁用 ConcurrencyMode 的约定(在EF 4.1 RTW中已删除)

  • Overriding the [ConcurrencyCheck] attribute on the POCO
  • Allowing a convention (removed in EF 4.1 RTW) to enable/disable the ConcurrencyMode based on some custom convention

最后,我认为 IsConcurrencyToken(false) IsNotConcurrencyToken更好()

这篇关于EF代码优先-IsConcurrencyToken()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆