I am using NHibernate version 2.0.0.4000.
In one of my queries I wanted to make use of the sql function dateadd to add a number of days. This wasn't registered so I created my own dialect and registered the function as follows:
RegisterFunction("adddays",
new SQLFunctionTemplate(NHibernateUtil.DateTime,
"dateadd(dd, ?1, ?2)"));
The registration gets hit and seems to work fine. I use the function in a DetachedCriteria query as follows:
...
Restrictions.LtProperty("DateColumn1"
Projections.SqlFunction("adddays", NHibernateUtil.DateTime,
Projections.Constant(days),
Projections.Property("DateColumn2"))
...
The criteria is returned from a method and passed of to another query. Upon the execution of the final query I get the following exception:
NHibernate.MappingException was caught
Message="No persister for: NHibernate.Criterion.SqlFunctionProjection"
Source="NHibernate"
StackTrace:
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName,
Boolean throwIfNotFound)
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
...
None of the blog posts that I have seen mention this problem. Can anybody help?
Cheers in advance. Nige.
Solved it.
The problem was caused by my usage elsewhere of Restrictions.Eq
rather than Restrictions.EqProperty
. The former does not have an overload for (IProjection,IProjection)
and so was treating the second projection as an object and passing it to a persister.
Thanks to anyone who investigated this. Nigel.
For No Persister exception in nhibernet solution is
just give a right click on the respective hbm file ->Properties->change the type Build Action-> to Embedded Resource
with the above step application will working fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With