即使 hbm 设置为嵌入式资源,NHibernate 也会给我这个错误:
关联引用未映射的类:UploadPromotions.Models.StagedPromotionImage
映射如下:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="UploadPromotions.Models"
namespace="UploadPromotions.Models">
<typedef
name="blobbedItem"
class="UploadPromotions.Models.Blobbed, UploadPromotions.Models">
<param name="classType">Legacy.Item,Legacy</param>
</typedef>
<typedef
name="blobbedSupplier"
class="UploadPromotions.Models.Blobbed, UploadPromotions.Models">
<param name="classType">Legacy.ItemFromSupplier,Legacy</param>
</typedef>
<typedef
name="photoText"
class="UploadPromotions.Models.Blobbed, UploadPromotions.Models">
<param name="classType">UploadPromotions.Models.PhotoText,UploadPromotions.Models</param>
</typedef>
<union-subclass name="StagedPromotionImage" extends="DiskImage">
<many-to-one name="CurrentStage" class="Stage" column="StageId" cascade="none"></many-to-one>
<set name="Stages" table="StageForPromotionsTable" cascade="none" batch-size="20" access="field.camelcase-underscore">
<key column="PromotionId"/>
<many-to-many class="Stage" column="StageId"/>
</set>
<many-to-one name="BaseImage" class="DiskImage" column="DiskImageId"></many-to-one>
<property name="Created"></property>
<property name="Modified"></property>
<property name ="Name"></property>
<property name="From" column="FromDate" not-null="true"></property>
<property name="To" column="ToDate" not-null="true"></property>
<property name="Description" type="AnsiString" length="100" not-null="true"></property>
<property name="Commited"></property>
<property not-null="true" name ="Art" type="NHibernate.Type.EnumStringType`1[[ADAutoTotal.UploadPromotions.Models.Art,ADAutoTotal.UploadPromotions.Models]], NHibernate"></property>
<property not-null="true" name ="Use" column="UsageType" type="NHibernate.Type.EnumStringType`1[[ADAutoTotal.UploadPromotions.Models.Use,ADAutoTotal.UploadPromotions.Models]], NHibernate"></property>
<component name="TemplateImage" class="Template">
<property name="TemplateName" not-null="true"></property>
<property name="Width" not-null="true" column="TemplateWidth"></property>
<property name="Height" not-null="true" column="TemplateHeight"></property>
</component>
<property name="Headline" type="photoText"></property>
<property name="Caption" type="photoText"></property>
<property name="Base64Url" not-null="false"></property>
<property name="Row" column="RowNumber" not-null="true"></property>
<property name="Position" not-null="true"></property>
<many-to-one name="CreatedBy" class="PromotionManager" column="ManagerId" cascade="none"></many-to-one>
<property name="Supplier" type="blobbedSupplier" not-null="false" length="1000"></property>
<property name="Item" column="ForItem" type="blobbedItem" not-null="false" length="1000"></property>
<many-to-one name="LastCommitedVersion" not-null="false" class="CommitedPromotionImage" column="LastCommitedVersionId"></many-to-one>
</union-subclass>
</hibernate-mapping>
我看不出有什么不对。至于用在什么地方:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="UploadPromotions.Models"
namespace="UploadPromotions.Models">
<class name="PromotionManager">
.......
<set name="StagedPromotionImages" batch-size="50" inverse="true" cascade="all-delete-orphan" access="field.camelcase-underscore">
<key column="CreatedById"></key>
<one-to-many class="StagedPromotionImage"/>
</set>
</class>
</hibernate-mapping>
和这里:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="UploadPromotions.Models"
namespace="UploadPromotions.Models">
<class name="Stage" table="StagedChanges">
.........
<set name="StagedImages" batch-size="50" inverse="true" cascade="all-delete-orphan" access="field.camelcase-underscore">
<key column="StageId"></key>
<one-to-many class="StagedPromotionImage"/>
</set>
............
</class>
</hibernate-mapping>
编辑:
好吧,我忘了在映射文件名中添加 .hbm 部分.....