0

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?

Heidi T.
  • 75
  • 1
  • 13
  • *CaseSensitive is unable* - do you mean *enabled*, *disabled*? – Rafalon Jun 29 '18 at 12:10
  • @Rafalon Yess, thank you for correction – Heidi T. Jun 29 '18 at 12:14
  • 2
    You should change the collate of the field in the sql.Here is a link that do it: https://stackoverflow.com/questions/33233168/define-sql-table-primary-key-as-case-sensitive-using-entity-framework-code-first and a list of the collate list is provided here: http://zarez.net/?p=1893 – AlbertoCh Jun 29 '18 at 12:27

1 Answers1

1

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; }
Heidi T.
  • 75
  • 1
  • 13