views:

332

answers:

1

Hi,

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.

+1  A: 

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

.Add( Expression.Eq( "InvDate", invoiceDate ) )
Darin Dimitrov
Thanks. Can't believe I missed something so simple!
Simon G
Don't worry, it happens all the time when using *magic strings* :-)
Darin Dimitrov