问题
This code does not compile as the ColumnType method is unknown in EF7 Beta7.
What is the new method to determine a special column type?
modelBuilder.Entity<Language>()
.Property(a => a.ISO639_ISO3166)
.ColumnType("char")
.MaxLength(5)
.Required();
回答1:
To change the column type you need to use the HasColumnType method:
modelBuilder.Entity<Language>()
.Property(a => a.ISO639_ISO3166)
.HasColumnType("char")
.MaxLength(5)
.Required();
And if you are targeting more than one relational provider with the same model then you probably want to specify a data type for each provider rather than a global one to be used for all relational providers:
modelBuilder.Entity<Language>()
.Property(a => a.ISO639_ISO3166)
.HasSqlServerColumnType("char")
.MaxLength(5)
.Required();
来源:https://stackoverflow.com/questions/32655634/entity-framework-7-beta7-has-no-columntype-anymore