Thanks a lot for quick reply. Unfortunately I'm not able to figure out
how to use SqlFunction in this complex condition and I'm not able to
google out anythink meaningful. Could you show me some sample code,
please? At the moment I'm stuck with making the Y/M calculation
(100*year(..) + month(..))...
var ym = Year.Value*100 + Month.Value;
var dateFromMonthProj =
Projections.SqlFunction("month",
NHibernateUtil.Int32, Projections.Property
("PurchaseDuration.DateFrom"));
var dateFromYearProj =
Projections.SqlFunction("year",
NHibernateUtil.Int32, Projections.Property
("PurchaseDuration.DateFrom"));
var dateToMonthProj =
Projections.SqlFunction("month",
NHibernateUtil.Int32, Projections.Property
("PurchaseDuration.DateTo"));
var dateToYearProj =
Projections.SqlFunction("year",
NHibernateUtil.Int32, Projections.Property
("PurchaseDuration.DateTo"));
IProjection calculatedYMFrom = null;
IProjection calculatedYMTo = null;
q.Add(Restrictions.Le(calculatedYMFrom, ym));
q.Add(Restrictions.Ge(calculatedYMTo, ym));
On 28 Dub, 11:17, Tuna Toksoz <[email protected]> wrote:
> Projections.SqlFunction or something like that should work.
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
>
> On Tue, Apr 28, 2009 at 12:14 PM, Filip Kinsky <[email protected]> wrote:
>
> > I need to use year() and month() functions in Criteria API to be able
> > to express a business filter constraint/filter. I have business object
> > with property Duration (NH compoenent) with DateFrom and DateTo
> > datetime fields. The user story is like "show me objects with duration
> > covering september 2009". I didn't found any other solution for
> > building the query without using year() and month() functions which
> > are available in HQL. Unfortunately I have to use Criteria API and I
> > can't find out how to use these functions (or some equivalents) in
> > Criteria API query. The solution in HQL looks like this:
>
> > var year = 2009; //user input
> > var month = 4; //user input
> > var ym = year * 100 + month;
> > var hql = ... :ym between 100 * year(f.Duration.DateFrom) + month
> > (f.Duration.DateFrom) and 100 * year(f.Duration.DateTo) + month
> > (f.Duration.DateTo)";
>
> > Is it possible to express this HQL condition in Criteria API query?
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---