views:

72

answers:

0

Hello:

Here's a pseudo criteria query I (think) I want to be able to use:

public IEnumerable<Allocation> ByResource(ResourceBase resource, DateRange period)
{
    return Session.CreateCriteria<Allocation>()
        .Add(Restrictions.Eq("Resource", resource))
        .Add(Restrictions.IsWithin("MembershipPeriod", period))
        .List<Allocation>();
}

The are several complications with this query, the most serious being that it won't compile, much less work. There is no such expression (ICriterion?) for IsWithin, which is the the problem I think I want to solve.

DateRange is a custom domain type which is essentially a range object which uses another domain type called a DatePoint as it's start and end. These classes exist to make it easy to handle precision and edge cases that come up with DateTimes from the domain's point of view.

The data base will only need to see two DateTimes though. DateRange has a user type (DateRangeUserType : ICompositeUserType) to easily map a DateRange to two DateTime columns in the db.

The IsWithin expression could just be Restrictions.Between("Birthday", start, end) if I just needed to know a simple DateTime. But I need select on periods of time that fall within a parameter period.

Can I do this? Is there a simpler approach?

Thanks & Cheers,

Berryl