实体框架代码优先-在域模型上使用接口

问题描述 投票:0回答:1

假设您有一个停车场,每个停车场可容纳x辆汽车,每辆汽车可以具有不同的属性。像这样:

public class CarPark
{
    public int Id { get; set; }

    public ICollection<ICar> Cars { get; set; }
}

public interface ICar
{
    string Model { get; set; }
}

public class Volvo : ICar
{
    public string Model { get; set; }

    public string Color { get; set; }
}

public class Bmw : ICar
{
    public string Model { get; set; }

    public int Wheels { get; set; }
}

当模型不同时,您如何处理这种情况?

c# .net entity-framework ef-code-first domain-driven-design
1个回答
0
投票

假设您的意思是由于接口的原因,您必须如何处理EF来弄乱模型的映射:您可以在DbContext的OnModelCreation方法中手动配置模型的转换。

查看更多信息:https://docs.microsoft.com/en-us/ef/core/modeling/

© www.soinside.com 2019 - 2024. All rights reserved.