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 '[ClassName]'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure th开发者_开发知识库at it is a valid primitive property.
What are the valid primitive types for EF Code First?
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.
精彩评论