Given the following tables, I am trying to return all distributions for this Resource that fall between a given date range using a query of criteria:
create table Resources ( ResourceId integer, ResourceName TEXT not null, BusinessId TEXT not null, OrganizationName TEXT not null, primary key (ResourceId) ) create table Allocations ( AllocationId integer, StartTime DATETIME not null, EndTime DATETIME not null, PostingTime DATETIME, ResourceId INTEGER, ActivityBaseId INTEGER, primary key (AllocationId), unique (StartTime, EndTime, ResourceId, ActivityBaseId) ) public Resource FetchFor(Resource resource, DateRange range) { var allocations = _session.CreateCriteria<Resource>() .CreateCriteria("Allocations") .Add(Restrictions.Between("EndTime", (DateTime)range.Start, (DateTime)range.End)) .List<Allocation>(); if (allocations.Count() > 0) resource.ReplaceAllocations(allocations); return resource; }
I get this exception when I run this:
failed: NHibernate.QueryException : could not resolve property: EndTime of: Domain.Model.Allocations.Allocation
The model is mapped, and I can easily save the resource and its associated distributions, as I do to test this Fetch request. Example NHib sql: NHibernate: INSERT INTO Allocations (StartTime, EndTime, PostingTime, ResourceId, ActivityBaseId) VALUES (@ p0, @ p1, @ p2, @ p3, @ p4); select last_insert_rowid (); @ p0 = 1/28/2010 12:00:00 AM, @ p1 = 1/28/2010 1:00:00 AM, @ p2 = NULL, @ p3 = 1, @ p4 = 4
The error message is misleading since NHIB clearly understands how to map Allocation.EndTime. You are welcome:
1) help solve the problem / clear the request in this post, and
2) list any favorite resources for studying nhib requests, especially if there are examples.
As I understand it, I do not understand that I am not using the Resource parameter in the example shown, since I have applied quite a lot (incorrectly?) Of the code from the example on Ayende placement . If I can get this connection request, I will turn it into a subquery for performance.
Thanks!
Berryl
=== NHib mapping =====
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"> <class xmlns="urn:nhibernate-mapping-2.2" name="Domain.Model.Allocations.Allocation, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="Allocations"> <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" unsaved-value="0"> <column name="AllocationId" /> <generator class="identity" /> </id> <property name="TimeRange" type="Data.UserTypes.AllocationTimeRangeUserType, Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> <column name="StartTime" not-null="true" unique-key="DomainSignature" /> <column name="EndTime" not-null="true" unique-key="DomainSignature" /> </property> <property name="PostingTime" type="System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="PostingTime" not-null="false" /> </property> <many-to-one class="Domain.Model.Resources.Resource, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" foreign-key="Resource_FK" name="Resource"> <column name="ResourceId" unique-key="DomainSignature" /> </many-to-one> <many-to-one class="Domain.Model.Activities.ActivityBase, Smack.ConstructionAdmin.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" foreign-key="ActivityBase_FK" name="Activity"> <column name="ActivityBaseId" unique-key="DomainSignature" /> </many-to-one>