我有一个有三个属性的简单对象。这将链接到一个具有三列的表,其中两列是主键(一个int,另一个是datetime)。
每当我尝试查询nhibernate时,都会收到以下错误消息:
无法解析属性:invdate of: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的引用,那么这就可以正常工作。
事先谢谢。