Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 区分大小写,实体框架代码优先_C#_Entity Framework_Entity Framework 6_Code First - Fatal编程技术网

C# 区分大小写,实体框架代码优先

C# 区分大小写,实体框架代码优先,c#,entity-framework,entity-framework-6,code-first,C#,Entity Framework,Entity Framework 6,Code First,我首先使用实体框架代码创建数据库。我查看了其他问题,但其中任何一个问题都没有明确的答案。我尝试将这两个键另存为表中的不同行: 12E60AED-7491-49B3-8006-78ECEA63B376 12e60aed-7491-49b3-8006-78ecea63b376 这是我的属性类: [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public class CaseSensitive : Attri

我首先使用实体框架代码创建数据库。我查看了其他问题,但其中任何一个问题都没有明确的答案。我尝试将这两个键另存为表中的不同行:

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; }
}
这是entityContex:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Add
                (new AttributeToColumnAnnotationConvention<CaseSensitive, bool>
                ("CaseSensitive", (property, attributes) => attributes.Single().IsEnabled));
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Add
(新属性为ColumnAnnotationConvention)
((区分大小写),(属性,属性)=>attributes.Single().IsEnabled));
}

但它不起作用,当我从tableDesigner中查看区分大小写时,排序规则区分大小写被禁用。我该怎么做呢?

我找到了答案。我在[Key]和这项工作之后写区分大小写。我不知道怎么…:

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

区分大小写无法-您的意思是启用、禁用吗?@Rafalon Yess,感谢您的更正您应该更改sql中字段的排序。这里有一个链接可以执行此操作:此处提供了排序列表的列表:因为您为您的属性赋予了一个属性,这就是它工作的原因。