在DBModelBuilder映射中使用TypeSafeEnumerations [英] Using TypeSafeEnumerations in DBModelBuilder Mapping

查看:85
本文介绍了在DBModelBuilder映射中使用TypeSafeEnumerations的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有以下类型的safeenum:

I have the following typesafeenum in my code:

 public sealed class ReeferMode : TypeSafeEnumeration
    {
        /// <inheritdoc />
        private ReeferMode(int value, string displayName) : base(value, displayName) { }

        public static readonly ReeferMode Continuous = new ReeferMode(0, "Continuous");
        public static readonly ReeferMode StartStop = new ReeferMode(1, "Start/Stop");
        public static readonly ReeferMode Automatic = new ReeferMode(2, "Automatic");
        public static readonly ReeferMode None = new ReeferMode(-1, "None");
    }

我试图使用以下内容将此枚举的值映射到我的数据库中的列:



and I am trying to map the values of this enum into a column in my DB using the following:

modelBuilder.ComplexType<ReeferMode>().Property(p=> p.Value).HasColumnName("ReeferMode");

我一直收到错误:

ExceptionMessage":"属性'Value'不是
'ReeferMode'类型的声明属性。使用Ignore方法或NotMappedAttribute数据批注验证是否未从模型中显式排除该属性。确保它是有效的原始属性。",

任何人都有任何想法如何这样做可以吗?

推荐答案

嗨katghoti,

Hi katghoti,

如果你想映射到特殊列,请使用model的属性而不是ComplexType。像这样:

If you want to map to special column, please use model's property instead of ComplexType. like this:

modelBuilder.Entity<YourEnityClass>().Property(t => t.relatedenumproperty.Value).HasColumnName("ReeferMode");

祝你好运,

Cole Wu


这篇关于在DBModelBuilder映射中使用TypeSafeEnumerations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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