如何将替代字段映射到Core EF Code First中的数据库?

我有一个抽象的基类,它具有name属性和[NotMapped]属性

public abstract class EntityBase
{
    [Key]
    public string id { get; set; }

    [NotMapped]
    abstract public string name { get; set; }
}

还有一个继承自EntityBase的子类

public class Person: EntityBase
{
    public override string name { get; set; }

    [Emailaddress]
    public string email { get; set; }

    [Phone]
    public string phone { get; set; }
}

我执行 add-migration Migration20191106 Update-Database 生成迁移文件并映射到数据库,但是它没有创建 name 字段,尝试更改EntityBase类:

[NotMapped]
public virtual string name { get; set; }

并更改Person类:

[Required]
public override string name { get; set; }

但是得到相同的结果。

我想知道带有[NotMapped]属性的名称字段如何映射到数据库,非常感谢!

lwt770906 回答:如何将替代字段映射到Core EF Code First中的数据库?

韦德

{NotMapped]告诉EF不要添加到数据库中。

本文链接:https://www.f2er.com/3153411.html

大家都在问