问题
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