有趣的 EF4 Code First 多对多关系问题
我有两个模型,一个 Report:
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 的联接表。我尝试了很多事情但没有成功,我知道必须有某种方法可以做到这一点,但我不知所措。希望其他人对如何做到这一点有一些见解。
I have two models, a Report:
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 });
}
}
and a 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
}
}
I want to be able to map the SortOrder property of the ChargeType to the join table of Report and ChargeType. I have tried many things with no success, and I know there has to be some way to do it but I am at a loss. Hopefully someone else has some insight on how this could be done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论