> using (var context = new PICSEntities(Config.model.SqlServer)) > { > var q = context.TransactionDetails.Where(t => t.Parcel.GoodsType.Description == "Rough") > .Where(t => t.Parcel.ParcelInventoryType.Description == "" + > "Inventory") > .GroupBy(t => new { f1 = t.Parcel.RSReference /*, f2 = t.TransactionHeader.TransactionType.Description */ }, (key, g) => > new > { > Parcel = key.f1, > BeginningInventory = g.Where(x => x.TransactionHeader.TransactionType.Description == "Beginning Inventory").Select(x => x.Cogs), > Purchase = g.Where(x => x.TransactionHeader.TransactionType.Description == "Purchase").Select(x => x.Cogs), > Transfer = g.Where(x => x.TransactionHeader.TransactionType.Description == "Internal Transfer").Select(x => x.Cogs), > Sale = g.Where(x => x.TransactionHeader.TransactionType.Description == "Sale").Select(x => x.Cogs) > }); >>
using (var context = new PICSEntities(Config.model.SqlServer)) { var q = context.TransactionDetails.Where(t => t.Parcel.GoodsType.Description == "Rough") .Where(t => t.Parcel.ParcelInventoryType.Description == "Inventory") .GroupBy(t => new { f1 = t.Parcel.RSReference /*, f2 = t.TransactionHeader.TransactionType.Description */ }, (key, g) => new { Parcel = key.f1, BeginningInventory = g.Where(x => x.TransactionHeader.TransactionType.Description == "Beginning Inventory").Sum(x => x.Cogs), Purchase = g.Where(x => x.TransactionHeader.TransactionType.Description == "Purchase").Sum(x => x.Cogs), Transfer = g.Where(x => x.TransactionHeader.TransactionType.Description == "Internal Transfer").Sum(x => x.Cogs), Sale = g.Where(x => x.TransactionHeader.TransactionType.Description == "Sale").Sum(x => x.Cogs) }); } using (var context = new PICSEntities(Config.model.SqlServer)) { var q = context.TransactionDetails.Where(t => t.Parcel.GoodsType.Description == "Rough") .Where(t => t.Parcel.ParcelInventoryType.Description == "Inventory") .GroupBy(t => new { f1 = t.Parcel.RSReference /*, f2 = t.TransactionHeader.TransactionType.Description */ }, (key, g) => new { Parcel = key.f1, BeginningInventory = g.FirstOrDefault(x => x.TransactionHeader.TransactionType.Description == "Beginning Inventory").Cogs, Purchase = g.FirstOrDefault(x => x.TransactionHeader.TransactionType.Description == "Purchase").Cogs, Transfer = g.FirstOrDefault(x => x.TransactionHeader.TransactionType.Description == "Internal Transfer").Cogs, Sale = g.FirstOrDefault(x => x.TransactionHeader.TransactionType.Description == "Sale").Cogs }); }PS: If you use LinqPad, you can not only quickly test variations but also copy paste the result easily (link below in my sig).