我正在尝试通过连接表"Communication_Recipients“将我创建的具有两个属性"SuccessRecipientList”和"FailRecipientList“的通信对象链接到用户对象。我想在连接表上使用一个鉴别器,而不是为它创建一个实际的域对象(使用连接表上的HasFailed位列)。有人知道这是否可以做到吗?
通信HBM:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataLogic" namespace="DataLogic.Domain">
<class name="DataLogic.Domain.Communication, DataLogic" table="Communications" >
<id name="Id" column="Id" type="Int32" unsaved-value="0">
<generator class="identity"></generator>
</id>
...
<set name="SuccessRecipientList" table="Communication_Recipients" lazy="true">
<key column="Communication_ID"></key>
<many-to-many class="MilkroundOnline.OnlineApplications.DataLogic.Domain.User, MilkroundOnline.OnlineApplications.DataLogic" column="User_ID"></many-to-many>
</set>
<set name="FailedRecipientList" table="Communication_Recipients" lazy="true" where="" >
<key column="Communication_ID"></key>
<many-to-many class="MilkroundOnline.OnlineApplications.DataLogic.Domain.User, MilkroundOnline.OnlineApplications.DataLogic" column="User_ID"></many-to-many>
</set>
</class>
</hibernate-mapping>数据库如下所示:
通信表
ID,
主题,
正文
用户表
ID,
名字,
姓氏
CommunicationUser表
CommunicationId,
UserId,
HasFailed(位)
提前感谢您的帮助!
抢夺
发布于 2010-06-18 01:42:30
不能,多对多表只能映射键(如果是列表或字典,则加上索引或映射键,如果是idbag,则映射其自己的id )。
您需要创建一个实体。但是,您可以从对象模型中投影这两个集:
//mapped set
public virtual ICollection<CommunicationUser> RecipientList { get; set; }
public virtual IEnumerable<User> SuccessRecipientList
{
get { return from cu in RecipientList where !cu.HasFailed select cu.User; }
}
public virtual IEnumerable<User> FailedRecipientList
{
get { return from cu in RecipientList where cu.HasFailed select cu.User; }
}https://stackoverflow.com/questions/3063663
复制相似问题