Fluent Nhibernate、复合键并且无法解析属性:错误消息
我有一个具有三个属性的简单对象。这链接到一个包含三列的表,其中两列是主键(一列是日期时间,另一列是日期时间)。
每当我尝试查询 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 的引用,那么这可以正常工作。
提前致谢。
I've got a simple object with three properties. This links to a table with three columns, with two of the columns being primary keys (one int the other a datetime).
Whenever I try and query nhibernate I get the following error message:
could not resolve property: invdate of:Models.Invoice
Have I missed something simple in setting up my mapping or am I doing my query wrong?
Object Code:
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
}
Mapping Code:
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 );
}
}
If I take out the reference to invdate in my query then this works fine.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该属性称为
InvDate
,而不是invdate
。试试这个:The property is called
InvDate
and notinvdate
. Try this: