代码中的nhibernate子类
我想通过代码在nhibernate中设置每个类层次结构的表继承。除子类外,其他所有内容都在XML映射文件中设置。如果我在xml中创建子类,一切都很好,但不是源于代码。这是我使用的代码-我的具体子类从未被创建:( Xml映射如下所示:代码中的nhibernate子类,nhibernate,Nhibernate,我想通过代码在nhibernate中设置每个类层次结构的表继承。除子类外,其他所有内容都在XML映射文件中设置。如果我在xml中创建子类,一切都很好,但不是源于代码。这是我使用的代码-我的具体子类从未被创建:( Xml映射如下所示: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Riz.Pcm.Domain.Busi
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Riz.Pcm.Domain.BusinessObjects" assembly="Riz.Pcm.Domain">
<class name="Riz.Pcm.Domain.BusinessObjects.TAction, Riz.Pcm.Domain" table="dbo.tAction" lazy="true">
<id name="Id" column="ID">
<generator class="guid" />
</id>
<discriminator type="String" formula="(select jt.Name from TJobType jt where jt.Id=JobTypeId)" insert="true" force="false"/>
<many-to-one name="Session" column="SessionID" class="TSession" />
<property name="Order" column="Order1" />
<property name="ProcessStart" column="ProcessStart" />
<property name="ProcessEnd" column="ProcessEnd" />
<property name="Status" column="Status" />
<many-to-one name="JobType" column="JobTypeID" class="TJobType" />
<many-to-one name="Unit" column="UnitID" class="TUnit" />
<bag name="TActionProperties" lazy="true" cascade="all-delete-orphan" inverse="true" >
<key column="ActionID"></key>
<one-to-many class="TActionProperty"></one-to-many>
</bag>
<!--<subclass name="Riz.Pcm.Domain.tActionSub" discriminator-value="ZPower"></subclass>-->
</class>
</hibernate-mapping>
我做错了什么?我在谷歌上找不到任何例子:(我们使用FluentNHibernate进行映射。用户实体是学习者、评估者、管理员等的基类 以下是一个例子:
public class UserMap : ClassMap<User>
{
public UserMap()
{
this.Id(x => x.Id);
this.Map(x => x.Active);
this.Component(
x => x.Address,
m =>
{
m.Map(x => x.Address1).Length(512);
m.Map(x => x.Address2);
m.Map(x => x.Address3);
m.Map(x => x.Address4);
m.Map(x => x.City);
m.Map(x => x.County);
m.Map(x => x.PostCode);
m.References(x => x.Country);
});
this.References(x => x.CreatedBy);
this.Map(x => x.CreatedDate).Not.Nullable();
this.DiscriminateSubClassesOnColumn("className").Length(64);
}
}
公共类用户映射:类映射
{
公共用户映射()
{
this.Id(x=>x.Id);
this.Map(x=>x.Active);
这个.组件(
x=>x.地址,
m=>
{
m、 Map(x=>x.Address1).Length(512);
m、 Map(x=>x.Address2);
m、 Map(x=>x.Address3);
m、 Map(x=>x.Address4);
m、 地图(x=>x.City);
m、 地图(x=>x.County);
m、 地图(x=>x.邮政编码);
m、 参考文献(x=>x.Country);
});
this.References(x=>x.CreatedBy);
this.Map(x=>x.CreatedDate).Not.Nullable();
此.DiscriminateSubClassesOnColumn(“className”).Length(64);
}
}
和派生类
public class LearnerMap : SubclassMap<Learner>
{
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="LearnerMap"/> class.
/// </summary>
public LearnerMap()
{
this.Map(x => x.DateOfBirth);
this.Map(x => x.NINumber);
this.Map(x => x.IscCodeId);
this.Map(x => x.ScnNo);
this.Map(x => x.ULN);
this.HasManyToMany(x => x.Organisation)
.ParentKeyColumn("userId")
.ChildKeyColumn("organisationId").Table(
"UserOrganisations");
}
公共类LearnerMap:子类映射
{
#区域构造函数和析构函数
///
///初始化类的新实例。
///
公共LearnerMap()
{
这个.Map(x=>x.DateOfBirth);
这个.Map(x=>x.NINumber);
this.Map(x=>x.IscCodeId);
这个.Map(x=>x.ScnNo);
this.Map(x=>x.ULN);
this.HasManyToMany(x=>x.organization)
.ParentKeyColumn(“用户ID”)
.ChildKeyColumn(“组织ID”).表(
“用户组织”);
}
希望这会有所帮助
public class LearnerMap : SubclassMap<Learner>
{
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="LearnerMap"/> class.
/// </summary>
public LearnerMap()
{
this.Map(x => x.DateOfBirth);
this.Map(x => x.NINumber);
this.Map(x => x.IscCodeId);
this.Map(x => x.ScnNo);
this.Map(x => x.ULN);
this.HasManyToMany(x => x.Organisation)
.ParentKeyColumn("userId")
.ChildKeyColumn("organisationId").Table(
"UserOrganisations");
}