簡體   English   中英

EF中的映射關系問題

[英]Problems with mapping relationship in EF

我有以下域模型(偽):

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 Configuration API中的給定關系說明來配置此映射,或者至少我不確定該怎么做。 我嘗試使用WithManySetupGroup開始映射,但是在這里我不能聲明CameraDisplay應該映射在CameraDisplayMap CameraDisplayMap開始,我無法將ID聲明為SetupGroup的外鍵。 我想念什么嗎?

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; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM