What are valid primitive properties in Entity Framework Code First?

后端 未结 1 511
迷失自我
迷失自我 2021-01-11 17:18

When I try to map a column to a char data type in my model class I get an error:

The property \'[ColumnName]\' is not a declared property on type \'

相关标签:
1条回答
  • 2021-01-11 17:35

    This is interesting but you really cannot map char property. I just checked it and if you want to have char(1) in the database you must use string property with following mapping:

    modelBuilder.Entity<MyEntity>()
                .Property(p => p.MyProperty)
                .HasMaxLength(1)
                .IsFixedLength()
                .IsUnicode(false);
    

    It is not only problem of Code-first. It is whole EF limitation because EDMX designer also doesn't show char type. I think allowed types will be same as described in CSDL reference for EDMX because code first is just wrapper around the same mapping infrastructure.

    0 讨论(0)
提交回复
热议问题