Entity Framework 7 Beta7 has no ColumnType anymore

你说的曾经没有我的故事 提交于 2019-12-13 06:08:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!