I was kindly helped with this Stack Overflow question.
Now I'm building up the query and need to add joins to other tables to bring in names and descriptions etc.
My query is this:
using (var ctx = new myEntities())
{
var pc = ctx.tblPostcodes.Where(z => z.Postcode == postcodeOutward)
.Select(x => new {postcodeId = x.PostcodeID}).Single();
int pcId = pc.postcodeId;
var q = ctx.tblPrices.OrderByDescending(x => x.Cost)
.Where(c => c.PostcodeID == pcId)
.Where(s => s.ItemID < 18)
.GroupBy(x => x.ItemID)
.Select(g => new { g, count = g.Count() })
.ToList()
.SelectMany(t => t.g.Select(b => b).Zip(Enumerable.Range(1, t.count), (j, i) => new { j.ItemID, j.Cost, j.SupplierID }));
foreach (var i in q)
{
sb.AppendFormat("ItemId = {0}, Cost = {1}, SupplierId = {2}<hr/>", i.ItemID, i.Cost, i.SupplierID);
}
}
And I'm trying to add the following join:
.Join(ctx.tblItems, it => it.ItemID, s => s.ItemID, (it, s) => new { it, s })
but it causes ambiguous invocation errors. Any ideas? I will need to add two more inner joins. I'm hoping to get one right and the other two will be easy (hopefully).