I have a question about hql language. I'm trying to generate DTO's via hql syntax on my WCF REST application. I have a problem with the second query. What is wrong with it? Is there any other way to reach the same result?
This works good.
session.CreateQuery(@"select new EntityTypeDTO(t.ID, t.Title, assc.ID)
from crmEntityType t
left outer join t.Association as assc").List<EntityTypeDTO>();
This does not work.
session.CreateQuery(@"select new EntityTypeDTO(t.ID, t.Title, assc.ID, new CustomFieldDTO(f.ID,f.EntityType,f.FieldType,f.Name,f.Value))
from crmEntityType t
join fetch t.Fields as f
left outer join t.Association as assc").List<EntityTypeDTO>();
Well, the
new Xxx(field1, field2, ...)
syntax is just a convenience way for creating those DTOs in a query. It is not a fully fledged programming language and as such it most probably won't support nestednew
calls like yournew EntityTypeDTO(..., new CustomFieldDTO(...))
.What you could do instead is select the fields into a
Object[]
and call the constructors yourself, e.g. like this: