我有以下域名模型(伪):
public class Camera {
public int Id { get; set; }
}
public class Display {
public int Id { get; set; }
}
public class SetupGroup {
public int Id { get; set; }
public virtual ICollection<CameraDisplayMap> Mappings { get; set; }
}
public class CameraDisplayMap {
public int Id { get; set; }
public Camera Camera { get; set; }
public Display Display { get; set; }
}
应按以下方式进行映射:
[Cameras]
Id (primary key)
[Displays]
Id (primary key)
[SetupGroup]
Id (primary key)
[CameraDisplayMap]
Id (foreign key to [SetupGroup]
Camera (foreign key to [Cameras])
Display (foreign key to [Display])
我知道数据模型并不理想,但它是支持我们的遗留应用程序之一的必要条件,这些应用程序使用应用程序逻辑处理大多数映射等。
目前,我无法使用EF Code First Fluent配置API中的给定关系指令配置此映射,或者至少我不确定如何执行此操作。我尝试使用SetupGroup
从WithMany
开始映射,但在此我无法声明Camera
和Display
应映射到CameraDisplayMap
。从CameraDisplayMap
开始,我无法将Id声明为SetupGroup
的外键。我错过了什么吗?
答案 0 :(得分:0)
CameraDisplayMap类应如下所示。
public class CameraDisplayMap {
public int Id { get; set; } //primary key
public int? SetupGroupId { get; set; } //foreign key to [SetupGroup]
public int? CameraId { get; set; } //foreign key to [Camera]
public int? DisplayId Displays { get; set; } //foreign key to [Display]
public virtual SetupGroup SetupGroups { get; set; }
public virtual Camera Cameras { get; set; }
public virtual Display Displays { get; set; }
}