首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多对多连接表鉴别器?

多对多连接表鉴别器?
EN

Stack Overflow用户
提问于 2010-06-18 00:40:56
回答 1查看 968关注 0票数 1

我正在尝试通过连接表"Communication_Recipients“将我创建的具有两个属性"SuccessRecipientList”和"FailRecipientList“的通信对象链接到用户对象。我想在连接表上使用一个鉴别器,而不是为它创建一个实际的域对象(使用连接表上的HasFailed位列)。有人知道这是否可以做到吗?

通信HBM:

代码语言:javascript
复制
<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(位)

提前感谢您的帮助!

抢夺

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-18 01:42:30

不能,多对多表只能映射键(如果是列表或字典,则加上索引或映射键,如果是idbag,则映射其自己的id )。

您需要创建一个实体。但是,您可以从对象模型中投影这两个集:

代码语言:javascript
复制
//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; }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3063663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档