CreateSqlQuery for an object with a formula property

When I try to query a table using CreateSqlQuery and convert it to an object containing a formula property, I get the following Adoexception.

"The value cannot be null. Parameter name: fieldName"

First, is it possible to use createqlquery in an entity that has a mapping of formulas?

+6
nhibernate
source share
2 answers

You can use CreateSQLQuery with formulas.

Here is a proof of concept. Display (class is not difficult to guess):

 <class name="Foo"> <id name="Id"> <generator class="hilo"/> </id> <property name="Data"/> <property name="DataX2" formula="Data * 2"/> </class> 

And here is the request:

 var foos = session.CreateSQLQuery( @" select Id as {foo.Id}, Data as {foo.Data}, Data + Data as {foo.Data2} from Foo ") .AddEntity("foo", typeof(Foo)) .List<Foo>(); 

If you look carefully, you will see that I am using a different formula than the one indicated in the comparison. NHibernate allows anything as long as all properties are in the request.

I suggest you read 17.1.2. Entity queries and the following items.

+7
source share

After a great search, I found the following

https://issues.jboss.org/browse/JBPAPP-6571

This seems to be a real bug in sleep mode, which they decided not to fix. There are some workarounds. I find it best to use aliases for property names. Aliases should be used as described here:

http://nhibernate.info/doc/nh/en/index.html#querysql-aliasreferences

+1
source share

All Articles