这里的EF新手并且遇到了一些困难。
我需要使用代码优先创建大约24个表。这些表中的每一个都有大约2-10个多对一关系,这些关系很简单,可以用1个表表示。以下是我的一些课程来说明我的结构...
namespace EMRS
{
public class ERecord
{
[Key]
public int PCRId { get; set; }
public virtual List<EFirstClass> EFirstClass {get; set;}
public virtual List<ESecondClass> ESecondClass { get; set; }
}
public class EFirstElement
{
[Key]
public int ElementId { get; set; }
public ElementCode stuff1 { get; set; } //eAirway.06
public string stuff2 { get; set; }
public int PCRId { get; set; }
public virtual ERecord EReportId { get; set; }
public virtual List<SubElement> Stuff4List { get; set; }
public virtual List<SubElement> Stuff5List { get; set; }
public virtual List<SubElement> Stuff6List { get; set; }
public virtual List<SubElement> Stuff7List { get; set; }
}
public class ESecondElement
{
[Key]
public int ElementId { get; set; }
public ElementCode Stuff9 { get; set; }
public ElementCode Stuff10 { get; set; }
public int PCRId { get; set; }
public virtual ERecord EReportId { get; set; }
public virtual List<SubElement> StuffList11 { get; set; }
public virtual List<SubElement> StuffList12 { get; set; }
public virtual List<SubElement> StuffList13 { get; set; }
public virtual List<SubElement> StuffList14 { get; set; }
public virtual List<SubElement> StuffList15 { get; set; }
public virtual List<SubElement> StuffList16 { get; set; }
public virtual List<SubElement> StuffList17 { get; set; }
}
public class SubElement
{
public int SubElementId { get; set; }
public string Value { get; set; }
public dynamic Type { get; set; }
public int ElementId { get; set; }
}
}
如果我要为元素类中的每个单独的1到多个关系创建一个类/表,我最终会得到许多具有完全相同结构的表。我想要做的是在SubElement类中引用一个引用多个类的外键。
我尝试了一个parentelement抽象类并在我的所有元素类中继承它,但是EF为该类创建了一个表(Parentelement)并将所有列放在该表中的所有Element类中。
有没有办法首先使用EF代码执行此操作?