您只需要将匿名类型分配给一个变量,试试这个。
var confRollUps = db.SaleConfirmation
.GroupBy(c => c.OfferId) // Ensure we get a list of unique/distinct offers
.Select(g => g.Select(i => new {
OfferId = i.OfferId,
ProductVariety = i.Product.Variety, // "Category" of product, will be the same across products for this offer. i.Product is a SQL Server Navigation property.
OfferPrice = i.Offer.Price, // The price of the product, set per offer. i.Offer is a SQL Server Navigation property.
OfferQty = i.Offer.Quantity, // The quantity of items that are expected to be sold before the offer expires
OfferDateClose =i.Offer.DateClose, // Date of when the offer expires
Total =g.Sum(ii => ii.Qty) // Sum up the Qty column, we don't care about ProdIds not matching
}));