如何在没有外键和不同名称的列的旧数据库上创建 HasMany 关系?我知道如何使用引用在 HeaderVersion 上创建一对一关系,但不知道如何创建从 Header 1 到 * HeaderVersion 的 HasMany。加入条件应为:
Header.Id1 = HeaderVersion.PId1 AND Header.Id2 = HeaderVersion.PId2
领域:
public class Header {
public virtual int Id1 { get; set; }
public virtual int Id2 { get; set; }
public virtual string Something { get; set; }
}
public class HeaderVersion {
public virtual int PId1 { get; set; }
public virtual int PId2 { get; set; }
public virtual int Version { get; set; }
public virtual string SomethingFoo { get; set; }
}
地图:
public HeaderMap() {
Table("Header");
LazyLoad();
CompositeId().KeyProperty(x => x.Id1, "Id1")
.KeyProperty(x => x.Id2, "Id2");
Map(x => x.Something).Column("Something");
}
public HeaderVersionMap() {
Table("HeaderVersion");
LazyLoad();
CompositeId().KeyProperty(x => x.PId1, "PId1")
.KeyProperty(x => x.PId2, "PId2")
.KeyProperty(x => x.Version, "Version");
Map(x => x.SomethingFoo).Column("SomethingFoo");
}