我對Nhibernate很新,我知道我的問題是不確定如何解決它。NHibernate加入不正確的字段
問題:用戶通過EmployeeID而不是UserID加入員工。這是造成問題,因爲它正在帶回不正確的細節。
Employee.hbm.xml
<many-to-one name="User" unique="true" column="UserID" />
User.hbm.xml
<one-to-one name="Employee" foreign-key="EmployeeID" class="Employee" lazy="false" />
Employee.cs
public virtual int EmployeeID { get; set; }
public virtual User User { get; set; } - This is UserID within the actual database
public virtual string EmailAddress { get; set; }
User.cs
public virtual int UserID { get; set; }
public virtual string Username { get; set; }
public virtual string Title { get; set; }
public virtual string Forename { get; set; }
public virtual string Surname { get; set; }
public virtual Employee Employee { get; set; }
以上是別人編碼,我試圖解決它。我試圖改變
<one-to-one name="Employee" foreign-key="UserID" class="Employee" lazy="false" />
但是,這仍然會導致問題。
我錯過了什麼嗎?在此先感謝您的幫助:-)
克萊爾
UPDATE
我是通過使一到一個,它會加入對用戶ID希望,但它仍然對加盟EmployeeID。任何人有任何其他想法?再次感謝:-)
Employee.hbm.xml
<one-to-one name="User" foreign-key="UserID" class="User" lazy="false" />
User.hbm.xml
<one-to-one name="Employee" foreign-key="UserID" class="Employee" lazy="false" />
您是否嘗試過使用'很多,TO-一個'而不是'一對一'? – Rippo 2011-05-10 10:26:19
你的外鍵在用戶身份上如何?這不是主要的嗎? – Andrew 2011-06-09 09:58:26