我想映射子类,但子对象上的外键不是Program
类上的ID。如何使用EF fluent API来定义这种关系?以下是我的课程。
public class Program
{
public int Id { get; set; }
public string ProgramNumber { get; set; }
public List<Child> Children { get; set; }
}
public class Child
{
public int Id { get; set;}
public string ProgramNumber { get; set; }
}
internal class ProgramMapping : EntityTypeConfiguration<Program>
{
public ProgramMapping()
{
ToTable("PROGRAMS");
HasKey(t => t.Id);
Property(t => t.Id).HasColumnName("ID");
Property(t => t.ProgramNumber).HasColumnName("PROGRAM_NUMBER");
}
}
internal class ChildMapping : EntityTypeConfiguration<Child>
{
public ChildMapping()
{
ToTable("CHILDREN");
HasKey(t => t.Id);
Property(t => t.Id).HasColumnName("ID");
Property(t => t.ProgramNumber).HasColumnName("PROGRAM_NUMBER");
}
}