实体框架7 Beta7不再具有ColumnType [英] Entity Framework 7 Beta7 has no ColumnType anymore

查看:42
本文介绍了实体框架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();


推荐答案

要更改列类型,您需要使用< a href = http://ef.readthedocs.org/en/latest/modeling/configuring.html#relational-data-type rel = nofollow> 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();

这篇关于实体框架7 Beta7不再具有ColumnType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆