【问题标题】:Case Sensitive with Entity Framework Code First实体框架代码优先区分大小写
【发布时间】:2018-06-29 12:05:38
【问题描述】:

我使用 Entity Framework CodeFirst 创建数据库。我查看其他问题,但其中任何一个都没有特别的答案。我尝试将这两个 KEY 作为不同的行保存到我的表中。:

12E60AED-7491-49B3-8006-78ECEA63B376 12e60aed-7491-49b3-8006-78ecea63b376

这是我的属性类:

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class CaseSensitive : Attribute
    {
            public CaseSensitive()
            {
                IsEnabled = true;
            }
            public bool IsEnabled { get; set; }
    }

这是我的数据库模型:

[Table("StandardBusinessDocument", Schema = "EFatura")]
    public class StandardBusinessDocument{
        [Key]
        [Column( TypeName= "varchar" , Order =0), MaxLength(36) ]
        [CaseSensitive]
        public string StandardBusinessDocumentGuid { get; set; }

        [Key]
        [Column(TypeName = "bit", Order = 1)]
        public Boolean StandardBusinessDocumentType { get; set; }

        [Column(TypeName = "varchar"), MaxLength(4)]
        public string Code{ get; set; }
}

这是 entityContext:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Add
                (new AttributeToColumnAnnotationConvention<CaseSensitive, bool>
                ("CaseSensitive", (property, attributes) => attributes.Single().IsEnabled));
}

但是当我从 tableDesigner-Collat​​ion CaseSensitive 中查看 caseSensitive 时,它​​不起作用。我该怎么做?

【问题讨论】:

标签: c# entity-framework entity-framework-6 code-first


【解决方案1】:

我找到了答案。我在 [Key] 和这项工作之后写 CaseSensitive。我不知道怎么做..:

[Key]
[CaseSensitive]
[Column( TypeName= "varchar" , Order =0), MaxLength(36) ]
public string StandardBusinessDocumentGuid { get; set; }

【讨论】:

  • 因为你为你的财产赋予了一个属性,这就是它起作用的原因。
猜你喜欢
  • 2018-11-18
  • 2011-11-17
  • 1970-01-01
  • 1970-01-01
  • 2017-09-01
  • 2014-05-23
  • 1970-01-01
  • 1970-01-01
  • 2013-12-29
相关资源
最近更新 更多