NHibernate QueryOver projection on many-to-one -
NHibernate QueryOver projection on many-to-one -
i trying queryover
working using projection on many-to-one
.
the class "post" has property many-to-one
"creator".
using
session.queryover(of post). select(projections. property(of post)(function(x) x.creator). withalias(function() postalias.creator)). transformusing(transformers.aliastobean(of post)()). list()
works each creator retrieved single query rather using bring together done when not using select/projection. if there 5 posts 5 different creators, 6 queries run 1 list of posts , 5 creators.
i tried working using joinalias
nil did job.
i searched solution, solutions found did utilize linq-provider not fit since actual "field list" passed via parameter.
does know if there solution other linq provider?
there solution, can utilize projections many-to-one
, custom result transformer.
disclaimer: can read vb syntax not have plenty courage write... expect can read c# , convert vb....
so can have projection this:
// aliases post root = null; creator creator = null; // projection list var columns = projections.projectionlist(); // root properties columns.add(projections.property(() => root.id).as("id")); columns.add(projections.property(() => root.text).as("text")); // reference properties columns.add(projections.property(() => creator.id).as("creator.id")); columns.add(projections.property(() => creator.firstname).as("creator.firstname")); // our projections have proper alias // alias related domain model // (because "creator.firstname" utilize in reflection) var query = session.queryover<post>(() => root) .joinalias(() => root.creator, () => creator) .select(columns)
now need smart transformer, our own custome 1 (plugability powerfulness of nhibernate). here can find one:
public class deeptransformerand can go on this
var list = query .transformusing(new deeptransformer<post>()) .list<post>()
check this:
fluent nhibernate - projectionlist - icriteria returning null values nhibernate aliastobean transformer associations nhibernate projection queryover
Comments
Post a Comment