我使用EF的代码第一种方法。我有以下三个类:
public class Inquiry
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public virtual ApplicationUser CreatedBy { get; set; }
public virtual Contractor Contractor { get; set; }
public IList<ApplicationUser> InquiryUsers { get; set; }
public IList<InquiryComment> Comments { get; set; }
public IList<HydroTechEmail> Emails { get; set; }
public InquiryState State { get; set; }
public List<string> Attachments { get; set; }
public DateTime? TimeOfCreation { get; set; }
public DateTime? TimeOfModification { get; set; }
}
public class HydroTechEmail
{
public Guid Id { get; set; }
public string Subject { get; set; }
public string Content { get; set; }
public string FromDisplayName { get; set; }
public string FromAddress { get; set; }
public List<string> ToDisplayName { get; set; }
public List<string> ToAddress { get; set; }
public HydroTechEmailState State { get; set; }
public DateTime? ReceivedTime { get; set; }
public virtual List<HydroTechEmailAttachment> Attachments { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
public class ApplicationUser
{
public Guid Id {get;set;}
public string Firstname {get;set;}
public string Lastname {get;set;}
}
我认为EF将为关系调查生成一些中间类 - &gt;许多电子邮件和查询 - &gt;许多应用用户。相反,它在ApplicationUser和HydroTechEmail类中创建了一个外键到Inquiry类。我应该如何创建这一对多的关系? 奇怪的是,对于Comments,它创建了一个名为InquiryComments的中间表。
答案 0 :(得分:0)
实体框架只会为多对多关系生成中间表。
对于一对多关系,不会创建任何中间表,因为没有必要。