Fluent Nhibernate、复合键并且无法解析属性:错误消息

发布于 2024-08-22 18:29:34 字数 1800 浏览 5 评论 0原文

我有一个具有三个属性的简单对象。这链接到一个包含三列的表,其中两列是主键(一列是日期时间,另一列是日期时间)。

每当我尝试查询 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轮廓§ 2024-08-29 18:29:34

该属性称为 InvDate,而不是 invdate。试试这个:

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

The property is called InvDate and not invdate. Try this:

.Add( Expression.Eq( "InvDate", invoiceDate ) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文