假设您有一个停车场,每个停车场可容纳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; }
}
当模型不同时,您如何处理这种情况?
假设您的意思是由于接口的原因,您必须如何处理EF来弄乱模型的映射:您可以在DbContext的OnModelCreation方法中手动配置模型的转换。