c# - ling sql group with join -
i have linq sql query:
var orderitems = orderitem in order_productitems //join style in products_styles on orderitem.style equals style.index orderitem.salesorderid == 123 group orderitem orderitem.frameno grp select new { frameno = grp.key, count = grp.select(x => x.frameno).count(), totalcost = grp.sum(x=>x.costprice), overallwidth = grp.single(x=>x.hardwaretype==3).overallheight, //name = style.name, //imagepath = style.external_image_path }; i'm trying data product_styles tag along, it's not working...
the above works, not when uncomment bits above....
include style in group, reference orderitem , style in select:
var orderitems = (from orderitem in order_productitems join style in products_styles on orderitem.style equals style.index orderitem.salesorderid == 123 group new { orderitem, style } orderitem.frameno grp select new { frameno = grp.key, count = grp.select(x => x.orderitem.frameno).count(), totalcost = grp.sum(x => x.orderitem.costprice), overallwidth = grp.single(x => x.orderitem.hardwaretype == 3).overallheight, name = grp.select(x => x.style.name).first(), imagepath = grp.select(x => x.style.external_image_path).first() }; you may have adjust suit needs, , may not compile as-is since don't have environment set test in, should give general idea.
Comments
Post a Comment