我有 3 节课:
public class WorkEntity
{
public virtual int WorkId { get; set; }
public virtual OrderExtensionEntity OrderExtension { get; set; }
}
public class OrderExtensionEntity
{
public virtual int Id { get; set; }
public virtual WorkEntity Work { get; set; }
public virtual IList<IssueInformation> Issues { get; set; }
}
public class IssueInformationEntity
{
public virtual int Id { get; set; }
public virtual long WorkId { get; set; }
}
它们被映射:
public class WorkMap : ClassMap<WorkEntity>
{
public WorkMap()
{
Id(x => x.WorkId).Column("ID_ZLECENIE").GeneratedBy.Sequence("SEQ_TAE_ZLECENIE");
HasOne(x => x.OrderExtension).Constrained();
}
}
public class OrderExtensionMap : ClassMap<OrderExtensionEntity>
{
public OrderExtensionMap()
{
LazyLoad();
Id(x => x.Id).Column("ID_ZLECENIE").GeneratedBy.Foreign("Work");
HasMany(x => x.IssueInformation).KeyColumn("FK_ZLECENIE");
}
}
public class IssueInformationMap : ClassMap<IssueInformationEntity>
{
public IssueInformationMap()
{
Id(x => x.Id).Column("ID_ZAD_ROZ_ADRES").GeneratedBy.Sequence("SEQ_ZAD_ROZ_ADRES");
Map(x => x.WorkId).Column("FK_ZLECENIE").Not.Nullable();
}
}
当我在数据库 (Oracle) 上创建记录时,我可以从表中获取所有信息。但我无法使用以下方法保存 OrderExtensionEntity:
var orderExtension = new OrderExtension();
orderExtension._some_variables_like_strings_to_be_saved_
Session.SaveOrUpdate(orderExtension)
如果我尝试这样做,它会告诉我“未解决的财产工作”和其他一些错误:
orderExtension.Work = new WorkEntity() { WorkId = 12345 };