2010-02-24 43 views
2

我有一個簡單的對象與三個屬性。這鏈接到一個有三列的表,其中兩列是主鍵(一個int是另一個日期時間)。流利Nhibernate,複合鍵,不能解決屬性:錯誤消息

每當我試着和查詢NHibernate的我收到以下錯誤信息:

無法解析屬性:invdate的:Models.Invoice

我錯過了一些簡單的設置我的映射或者我在做我的查詢錯誤?

對象代碼:

public class Invoice 
{ 
    public Invoice() { } 

    #region Properties 

    public virtual int Acct_Link { get; private set; } 
    public virtual DateTime Added { get; private set; } 
    public virtual DateTime InvDate { get; private set; } 

    public static Invoice GetInvoiceByFluent(int accountId, DateTime invoiceDate) 
    { 
     Invoice invoice; 

     using (ISession session = FluentNHibernateHelper.OpenSession()) 
     { 
      invoice = session 
       .CreateCriteria<Invoice>() 
       .SetMaxResults(1) 
       .Add(Expression.Eq("Acct_Link", accountId)) 
       .Add(Expression.Eq("invdate", invoiceDate)) 
       .UniqueResult<Invoice>(); 
     } 

     return invoice; 
    } 

    #region Nhibernate overrides 

    public override bool Equals(object obj) 
    { 
     if (obj == null) 
      return false; 

     Invoice i = obj as Invoice; 

     return this.GetHashCode() == i.GetHashCode(); 
    } 

    public override int GetHashCode() 
    { 
     return this.Acct_Link.GetHashCode()^this.InvDate.GetHashCode(); 
    } 

    #endregion 
} 

映射代碼:

public class InvoiceMap: ClassMap<Invoice> 
{ 
    public InvoiceMap() 
    { 
     Table("Invoice"); 

     CompositeId() 
      .KeyProperty(i => i.Acct_Link, "Acct_Link") 
      .KeyProperty(i => i.InvDate, "InvDate"); 

     Map(i => i.Added); 
    } 
} 

如果我拿出參考我的查詢到invdate那麼這個工作正常。

在此先感謝。

回答

1

該物業被稱爲InvDate而不是invdate。試試這個:

.Add(Expression.Eq("InvDate", invoiceDate)) 
+0

謝謝。不能相信我錯過了這麼簡單的事情! – lancscoder 2010-02-24 15:36:51

+1

不用擔心,使用*魔法字符串時,它總是會發生* :-) – 2010-02-24 15:42:31