我有两节课
public class ProgramObject
{
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual Commisioning planCommisioning { get; set; }
public virtual Commisioning factCommisioning { get; set; }
}
public class Commisioning
{
public virtual long Id { get; set; }
public virtual decimal? FirstQuarter { get; set; }
public virtual ProgramObject planCommisioningRef { get; set; }
public virtual ProgramObject factCommisioningRef { get; set; }
}
和地图类
public class ProgramObjectMap : ClassMap<ProgramObject>
{
public ProgramObjectMap()
{
Table("Ipo_ProgramObject");
Id(x => x.Id).GeneratedBy.Increment();
Map(x => x.SuplyOrgName).Column("SuplyOrgName");
References(x => x.factPowerCommisioning).Column("factCommisioningID");
References(x => x.planPowerCommisioning).Column("planCommisioningID");
}
}
public class CommisioningMap : ClassMap<Commisioning>
{
public CommisioningMap()
{
Table("Ipo_Commisioning");
Id(x => x.Id).GeneratedBy.Increment();
Map(x => x.FirstQuarter).Column("FirstQuarter");
HasOne(x => x.factCommisioningRef)
.Cascade.All();
HasOne(x => x.planCommisioningRef)
.Cascade.All();
}
}
当我尝试提交时,出现异常“对象引用了未保存的瞬态实例”。我在映射方面做错了什么?
为了保存对象,我使用以下代码:
private static void Save(SessionManager sManager, ProgramObject ProgramObject, IpoConversions conversions)
{
sManager.OpenSession();
var currSession = sManager.CurrentSession;
using (ITransaction tx = currSession.BeginTransaction())
{
currSession.Save(ProgramObject);
tx.Commit();
}
}
我认为映射有问题。