var result = from outer in
(from customerobj in context.customer
join regobj in context.register
on customerobj.customer_no equals regobj.customer_no
join invnobj in context.inventory
on regobj.pos_sku equals invnobj.pos_sku
join sub_cat in context.sub_category
on invnobj.category equals sub_cat.category_id
select new
{
altSKU = invnobj.alt_sku,
subcatdescription = sub_cat.description,
compute_0003description = invnobj.product_description == null ? " " : invnobj.product_description + " " + (invnobj.release_no.HasValue ? invnobj.release_no.Value.ToString() : "") + " " +
(invnobj.description == null ? "" : invnobj.description),
regreceitno = regobj.receipt_no,
qtycompute_0005 = regobj.quantity,
tmpproddescription = invnobj.product_description,
tmpinvdescription = invnobj.description,
tmpinvreleaseno = invnobj.release_no,
tmpsubrelaseno = invnobj.sub_release_no,
})
group outer by new
{
grpaltsku = outer.altSKU,
grpsubcatdesp = outer.subcatdescription,
grpprodescition = outer.tmpproddescription,
grpinvdescription = outer.tmpinvdescription,
grpinvrelno = outer.tmpinvreleaseno,
grpsubrelnob = outer.tmpsubrelaseno,
grprectno = outer.regreceitno,
grp003grpdesc = outer.compute_0003description,
} into g
select new d_customer_past_sale_items_entity
{
compute_0005 = g.Sum(p => p.qtycompute_0005),
compute_0003 = g.Key.grp003grpdesc,
inventory_alt_sku = g.Key.grpaltsku,
register_receipt_no = g.Key.grprectno,
sub_category_description = g.Key.grpsubcatdesp
};