我有两个模型,一个报告:
public class Report
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ChargeType ChargeTypes { get; set; }
}
public class ReportConfiguration : EntityConfiguration<Report>
{
public ReportConfiguration()
{
MapSingleType(r => new { r.Id, r.Name }).ToTable("Report");
HasMany(r => r.ChargeTypes)
.WithMany(c => c.Reports)
.Map("Report_ChargeType", (r,c) => new { ReportId = r.Id,
ChargeTypeId = c.Id });
}
}
和 ChargeType:
public class ChargeType
{
public int Id { get; set; }
public string Name { get; set; }
public int SortOrder { get; set; }
public virtual Report Reports { get; set; }
}
public class ChargeTypeConfiguration : EntityConfiguration<ChargeType>
{
public ReportConfiguration()
{
MapSingleType(c => new { c.Id, c.Name }).ToTable("ChargeType");
// map SortOrder property to join table "Report_ChargeType"
MapSingleType(c => c.SortOrder).ToTable("Report_ChargeType"); // doesn't work
}
}
我希望能够将 ChargeType 的 SortOrder 属性映射到 Report 和 ChargeType 的连接表。我尝试了很多事情都没有成功,我知道必须有办法做到这一点,但我不知所措。希望其他人对如何做到这一点有所了解。