My domain model works with dates a lot, and so there is a DateRange
class to find out things such as does one period of time include
another, i.e.:
var allWeek = new DateRange(DateTime.Today, DateTime.Today.AddDays
(7));
var thruTomorrow = new DateRange(DateTime.Today,
DateTime.Today.AddDays(1));
var isIncluded = allWeek.Includes(thruTomorrow);
Assert.That(isIncluded, Is.True);
Given an Allocation class that looks something like this:
public class Allocation : Entity {
public virtual ResourceBase Resource { get; private set; }
public virtual ActivityBase Activity { get; private set; }
public virtual DateRange TimePeriod { get; private set; }
}
With a mapping that looks something like this (note that DateRange has
a ICompositeUserType, TimePeriodUserType, which stores the period as
two DateTime types in the db):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="">
<class name=" ….Allocation,
<property name="TimePeriod"
type="...NHibernate.UserTypes.TimePeriodUserType,
<column name="StartDateTime" />
<column name="EndDateTime" />
</property>
<many-to-one foreign-key="FK_AllocationToActivity" fetch="join"
not-null="true" cascade="save-update" name="Activity"
column="ActivityBaseID" />
<many-to-one foreign-key="FK_AllocationToResource" fetch="join"
not-null="true" cascade="save-update" name="Resource"
column="ResourceBaseID" />
</class>
</hibernate-mapping>
I’d like to have a query to find retrieve the allocations that were
incurred by a given resource over a given period of time. I’m a newb
with NHib, and my criteria query to try and do this so far looks like:
public IEnumerable<Allocation> ByResource(ResourceBase resource,
DateRange period) {
return Session.CreateCriteria<Allocation>()
.Add(Restrictions.Eq("Resource", resource))
.Add(Restrictions.Eq("TimePeriod", period))
.Future<Allocation>();
}
I used Eq on the “TimePeriod” just to see if the mapping works
mechanically, which it seems to (it doesn’t generate an error). It may
not work logically, as two test allocations that “I know” should be
returned are not returned, but I’m not going to worry about that right
now, since the point here is to come up with an operation more like
the Includes one at the beginning of this posting.
Can someone give me an idea as to how to do that?
Thanks,
Berryl
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---