c# - How to get out values from object when using Projections -
c# - How to get out values from object when using Projections -
how out values object when using projections. suggestions? illustration of code
var productsgrouped = session.queryover<product>() .select(projections.group<product>(p => p.category), projections.avg<product>(p => p.unitprice), projections.sum<product>(p => p.unitsonstock), projections.rowcount()) .list<object[]>(); foreach (var product in productsgrouped) { console.writeline(product.category); //dont work }
what need here, utilize dto object
public class productdto { public virtual string category { ; set; } public virtual decimal unitprice { get; set; } public virtual decimal unitsonstock { get; set; } public virtual int rowcount { get; set; } }
and utilize dto create alias
productdto dto = null; var productsgrouped = session.queryover<product>() // let's fill projection list sum, count als alias .select(projections.projectionlist() .add(projections.group<product>(p => p.category) .withalias(() => dto.category)) .add(projections.avg<product>(p => p.unitprice) .withalias(() => dto.unitprice)) .add(projections.sum<product>(p => p.unitsonstock) .withalias(() => dto.unitsonstock)) .add(projections.rowcount() .withalias(() => dto.rowcount)) ) // here instruct nhibernate convert projection our object dto .transformusing(transformers.aliastobean<productdto>()) // typed result .list<productdto>(); // qualified object foreach (var product in productsgrouped) { console.writeline(product.category); //dont work }
c# nhibernate
Comments
Post a Comment