0

I have a Database table in which table i have a column that is char type. EF originally is not able to map char types.

I did a bit search and i found this and this but it does not solve my problem. Here is what i tried

modelBuilder.HasDefaultSchema("****");
        modelBuilder.Entity<DistinaBase>()
            .Property(e => e.ProprietaCompomente).IsFixedLength().HasMaxLength(1).HasColumnType("Char").IsUnicode(false);

And in my model i wrote this

[Column("PROPRIETA_COMPONENTE",TypeName ="Char")]        
    public string ProprietaCompomente { get; set; }

So my question is: Am i missing something in my way mapping char types in EF?

Community
  • 1
  • 1
dim mik
  • 939
  • 1
  • 10
  • 30
  • What problem do you have with the code? Do you get an exception? Is ProprietaCompomente null after query? Or...? – mortb May 16 '17 at 10:44
  • @mortb The exception is thrown in my View when trying to put data on a grid. ProprietaCompomente in the table is a char type. If in my model i try to pass it as `public char ProprietaCompomente {get;set;}` i got the exception that EF does not maps char type. If i change it to `public string ProprietaCompomente {get;set;} ` the exception that is throw has with NullReffernceException because in my table ProprietaCompomente is char. – dim mik May 16 '17 at 11:03
  • Note that column name above is "PROPRIETA_COMPO**N**ENTE" and the variable is "ProprietaCompo**m**ente" – Henrique Sep 20 '17 at 12:31

0 Answers0