nHibernate, mapping two properties to the same class

[亡魂溺海] 提交于 2020-01-02 06:07:11

问题


I have a Mailclass, where I want to save both the sender and the recipient as a reference to the User class;

    public class dbMail : Entity
{
    public virtual int ThreadID { get; set; }
    public virtual dbUser From { get; set; }
    public virtual dbUser To { get; set; }
    public virtual DateTime MailDate { get; set; }
    public virtual string MailText { get; set; }
    public virtual bool IsRead { get; set; }
}

and the mapping:

<id name="ID">
  <generator class="identity" />
</id>
<property name="ThreadID" />

<many-to-one name="From" class="dbUser" column="From"/>
<many-to-one name="To" class="dbUser" column="To"/>
<property name="MailDate" />
<property name="MailText" type="StringClob">
  <column name="MailText" sql-type="text" />
</property>
<property name="IsRead" />

However, when trying to update the database, this error occurs:

Duplicate property mapping of dbUser found in Domain.Model.dbMail

回答1:


I've your same mapping situation and it works. The only difference is:

<many-to-one cascade="all" ...

Try this solution but if this doesn't works you have to show update code and/or dbUser code and mapping for further investigation.



来源:https://stackoverflow.com/questions/6491455/nhibernate-mapping-two-properties-to-the-same-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!