views:

497

answers:

1

Mapping-File:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="DaVinci"
               namespace="DaVinci.Domain">
  <class name="Waehrungskurs" table="WAEHRUNGSKURSE">
    <id name="Id" column="ID">
      <generator class="native" />
    </id>
    <property name="ISOCode" column="ISO" />
    <property name="AktuellerKurs" column="AKTKURS" />
    <property name="Kursart" column="KIND_OF_KURS" />
    <property name="WährungstabkurseId" column="WAEHRUNGSTABKURSE_ID" />
    <property name="Departure" column="DEPARTURE" />
    <property name="Datum" column="DATE_TIME" />
    <property name="RealerKurs" column="REALKURS" />
    <property name="Gültig" column="GUELTIG" />    
  </class>
</hibernate-mapping>

Domain.cs:
...
public virtual double AktuellerKurs { get; set; }
public virtual DateTime Datum { get; set;}
public virtual DateTime Gültig { get; set; }
public virtual int Id { get; set; }
public virtual string ISOCode { get; set; }
public virtual int Kursart { get; set; }
public virtual double RealerKurs { get; set; }
public virtual int WährungstabkurseId { get; set; }
...

I get a NHibernate.QueryException ("could not resolve property: Datum.Date of: DaVinci.Domain.Waehrungskurs") when i call the following function:

    public static Domain.Waehrungskurs GetByISOAndKursartAndDate(string isocode, int kursart, DateTime datum)
    {            

        return (from WK in session.Linq<DaVinci.Domain.Waehrungskurs>()                    
                where WK.ISOCode == isocode
                            &&
                      WK.Kursart == kursart
                            &&
                      WK.Datum.Date == datum.Date
                orderby WK.Id descending
                select WK).First();
    }

When i delete the search-condition "WK.Datum.Date == datum.Date", the function works fine.

Any ideas why the property cannot be found?

A: 

The date-property of date time is not found because it's not implemented. Please write a patch for this class

Paco
This is a pretty glaring omission given that those functions can be trivially implemented by calling the one in the framework. Rather than complain I've written a patch for every function that file, all the text stuff too, plus I added DayOfWeek, DayOfYear and Date. How do I submit it?
Gareth Farrington
@Gareth Farrington: That's great! Maybe you can submit it as a subversion patch to the authors of NHibernate.Linq?
Paco
I just went through updating all the libs (Nhibernate/ActiveRecord) for our project and I see that Linq is now part of the NHibernate core. The file I wrote the patch for doesn't even exist in the new code. Tests with the new code show that this issue isn't fixed yet. Access from the Select clause works but access from GroupBy does not.We decided to just modify our tables instead. We are adding Day/Month/Year integer columns for the dates that we need to do grouping/where clauses on. Its just less painful and possibly more performant.I'm not sure how I should proceed from here.
Gareth Farrington
NHcorelinq != NHcontrib linqThe linq provider in the trunk is a totally new linq provider, different than the linq provider in NHcontrib. The old provider is a little bit more stable, and has implemented the most basic features completely. The new linq provider will be a full linq provider and will finally implement everything in HQL. The old provider is based on criteria. I also use workarounds with the NHcontrib provider until the new linqprovider is finished.
Paco