加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 实体框架代码中有效的原始属性是什么?

发布时间:2020-12-15 06:47:23 所属栏目:百科 来源:网络整理
导读:当我尝试将列映射到我的模型类中的char数据类型时,我会收到一个错误: 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 Ignor
当我尝试将列映射到我的模型类中的char数据类型时,我会收到一个错误:

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 that it is a valid primitive
property.

EF Code First的有效原始类型是什么?

解决方法

这很有趣,但你真的不能映射char属性.我只是检查它,如果你想在数据库中有char(1),你必须使用带有以下映射的字符串属性:
modelBuilder.Entity<MyEntity>()
            .Property(p => p.MyProperty)
            .HasMaxLength(1)
            .IsFixedLength()
            .IsUnicode(false);

这不仅仅是Code-first的问题.这是整个EF限制,因为EDMX设计师也不显示字符类型.我认为允许的类型将与EDMX的CSDL reference中所述相同,因为代码首先只是围绕相同的映射基础设施进行包装.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读