实体框架7 Beta7不再具有ColumnType

问题描述:

该代码无法编译,因为 ColumnType 方法在 EF7 Beta7 中是未知的。

This code does not compile as the ColumnType method is unknown in EF7 Beta7.

什么是

 modelBuilder.Entity<Language>()
                .Property(a => a.ISO639_ISO3166)
                .ColumnType("char")
                .MaxLength(5)
                .Required();


要更改列类型,您需要使用 HasColumnType 方法:

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();