微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

EF Core 5.0 无法映射属性

如何解决EF Core 5.0 无法映射属性

我有一个名为estimateType 的值对象和另一个名为Proposal 的实体。 提案可以有一种估计类型,而estimateType 是一种Value 类型。

public record EstimateType {

    public EstimateName Name { get; private set; }

    public bool IsDeleted { get; private set; }

    public string Comment { get; private set; }

    public DateTime LastModified { get; private set; }

    public EstimateType (EstimateName name,bool isDeleted,string comment,DateTime lastModified) {

        Name = name;
        IsDeleted = isDeleted;
        Comment = comment;
        LastModified = lastModified;
    }

}

还有一个叫做 Proposal 的类。

public class Proposal {

    private Guid _id;
    private EstimateType _estimateType;

    private Proposal () {

    }
    public Guid Id => _id;
    public EstimateType EstimateType => _estimateType;

    public static Proposal Create (EstimateType estimateType) {

        return new Proposal {
            _id = Guid.NewGuid (),_estimateType = estimateType
        };

    }
}

这是我的配置方法

public void Configure (EntityTypeBuilder<Proposal> builder) {
    builder
        .Property (p => p.Id)
        .HasField ("_id")
        .UsePropertyAccessMode (PropertyAccessMode.Field);

    builder
        .Property (p => p.EstimateType)
        .HasField ("_estimateType")
        .UsePropertyAccessMode (PropertyAccessMode.Field);

    builder.Ignore (p => p.DomainEvents);

}

但是在进行 ef 迁移时我遇到了错误 属性“Proposal.EstimateType”的类型为“EstimateType”

当前数据库提供程序不支持。更改属性 CLR 类型,或使用“[NotMapped]”特性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略该属性

public enum EstimateName
    {
        A = 0,B = 1,C = 2,D = 3
    }

在这里遗漏了什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。