第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在實體框架中創(chuàng)建多對多映射?

如何在實體框架中創(chuàng)建多對多映射?

C#
回首憶惘然 2019-10-26 13:19:47
在這種情況下,我有2個實體,例如Contract,Media。public class Media : Entity{    public string Name {get; set;}    public bool Enabled    *//other properties can be ignored..*}public class Contract : Entity{    public string Code {get; set;}    *//other properties can be ignored..*}合同有許多媒體,看來它們是多對多的。但??!首先在EF代碼,我需要在ContractMedia表(EF自動生成)中再添加3個字段。例如StartDate,EndDate和Price。無法將其添加到媒體實體中。在這種情況下如何映射?
查看完整描述

2 回答

?
楊__羊羊

TA貢獻1943條經(jīng)驗 獲得超7個贊

無需使用Fluent API,即可添加到@Tomas答案。


public class Media // One entity table

{

    public int Id { get; set; }


    public string Name { get; set; }


    public virtual ICollection<ContractMedia> ContractMedias { get; set; }

}


public class Contract // Second entity table

{

    public int Id { get; set; }


    public string Code { get; set }


    public virtual ICollection<ContractMedia> ContractMedias { get; set; }

}


public class ContractMedia // Association table implemented as entity

{

    [Key]

    [Column(Order = 0)]

    [ForeignKey("Media")]

    public int MediaId { get; set; }


    [Key]

    [Column(Order = 1)]

    [ForeignKey("Contract")]

    public int ContractId { get; set; }


    public DateTime StartDate { get; set; }


    public DateTime EndDate { get; set; }


    public double Price { get; set; }


    public virtual Media Media { get; set; }


    public virtual Contract Contract { get; set; }

}


查看完整回答
反對 回復(fù) 2019-10-26
  • 2 回答
  • 0 關(guān)注
  • 352 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號