Case Sensitive with Entity Framework Code First

c# code-first entity-framework entity-framework-6

Question

I create database with Entity Framework CodeFirst. I look other questions but any of them has not spesific answer.I try to save this two KEY's as a different rows to my table.:

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

This is my class for attribute:

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

This is my db model:

[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; }
}

An this is entityContex:

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

But it doesnt work, when I look caseSensitive from tableDesigner-Collation CaseSensitive is disabled. How can I work it?

1
0
6/29/2018 12:13:09 PM

Accepted Answer

I find answer. I write CaseSensitive after [Key] and this work. I don't know how..:

[Key]
[CaseSensitive]
[Column( TypeName= "varchar" , Order =0), MaxLength(36) ]
public string StandardBusinessDocumentGuid { get; set; }
1
6/29/2018 12:39:15 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow