区分大小写 Entity Framework 代码优先
Case Sensitive with Entity Framework Code First
我使用 Entity Framework CodeFirst 创建数据库。我看了其他问题,但其中任何一个都没有具体 answer.I 尝试将这两个 KEY 作为不同的行保存到我的 table.:
12E60AED-7491-49B3-8006-78ECEA63B376
12e60aed-7491-49b3-8006-78ecea63b376
这是我的 class 属性:
[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; }
}
这是 entityContex:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Add
(new AttributeToColumnAnnotationConvention<CaseSensitive, bool>
("CaseSensitive", (property, attributes) => attributes.Single().IsEnabled));
}
但它不起作用,当我从 tableDesigner-Collation CaseSensitive 中查看 caseSensitive 时,它已被禁用。我该如何操作?
我找到了答案。我在 [Key] 之后写 CaseSensitive 和这项工作。我不知道怎么...:[=11=]
[Key]
[CaseSensitive]
[Column( TypeName= "varchar" , Order =0), MaxLength(36) ]
public string StandardBusinessDocumentGuid { get; set; }
我使用 Entity Framework CodeFirst 创建数据库。我看了其他问题,但其中任何一个都没有具体 answer.I 尝试将这两个 KEY 作为不同的行保存到我的 table.:
12E60AED-7491-49B3-8006-78ECEA63B376 12e60aed-7491-49b3-8006-78ecea63b376
这是我的 class 属性:
[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; }
}
这是 entityContex:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Add
(new AttributeToColumnAnnotationConvention<CaseSensitive, bool>
("CaseSensitive", (property, attributes) => attributes.Single().IsEnabled));
}
但它不起作用,当我从 tableDesigner-Collation CaseSensitive 中查看 caseSensitive 时,它已被禁用。我该如何操作?
我找到了答案。我在 [Key] 之后写 CaseSensitive 和这项工作。我不知道怎么...:[=11=]
[Key]
[CaseSensitive]
[Column( TypeName= "varchar" , Order =0), MaxLength(36) ]
public string StandardBusinessDocumentGuid { get; set; }