How can I return a component type of a mapped class using the Criteria
API. I guess I have to use a projection, but if I project on the
component I get an exception telling me it doesn't map to a single
property.
I can do it using HQL though, but I'd rather use the Criteria API if
possible.
In HQL I do like this:
var criteria = session.CreateQuery("select e.Component from Entity e
where e.Id = :id");
criteria.SetParameter("id", id);
return criteria.UniqueResult<ComponentType>();
What I'd like to do is something like this with the Criteria API:
var criteria = session.CreateCriteria(typeof(Entity), "e");
criteria.Add(Restrictions.IdEq(id));
criteria.SetProjection(Projections.Property("e.Component");
return criteria.UniqueResult<ComponentType>();
Even though the second example is more verbose, I believe it's safer
in regards of type-safety (and spelling).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---