本文介绍了nHibernate,将两个属性映射到同一类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Mailclass,我想在其中保存发件人和收件人作为对User类的引用;
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; }
}
和映射:
<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
推荐答案
我有相同的映射情况,并且可以正常工作.唯一的区别是:
I've your same mapping situation and it works. The only difference is:
<many-to-one cascade="all" ...
尝试此解决方案,但如果此方法不起作用,则必须显示更新代码和/或dbUser代码以及映射以供进一步研究.
Try this solution but if this doesn't works you have to show update code and/or dbUser code and mapping for further investigation.
这篇关于nHibernate,将两个属性映射到同一类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!