I'm very new to LINQ and one of my first attempts at using it had to be super complicated!
I am trying to adapt the accepted answer in this Stack Over question.
I have written it thus:
using (var ctx = new MyEntities())
{
var q = ctx.tblPrices.OrderByDescending(x => x.Cost)
.GroupBy(x => x.ItemID)
.Select(g => new {g, count = g.Count()})
.SelectMany(t => t.g.Select(b => b).Zip(Enumerable.Range(1, t.count), (j, i) => new {j.WebPrice, j.PriceID, j.ItemID}));
foreach (var i in q)
{
sb.AppendFormat("Id = {0}, Name = {1}, ItemId = {2}<hr/>", i.WebPrice, i.PriceID, i.ItemID);
}
}
Basically, I want to return the cheapest price for the same items from different suppliers.
However, when I run the project I get the following very long error message and I have no idea what it means. But it looks pretty serious!
LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable
1[<>f__AnonymousType5
3[System.Nullable1[System.Decimal], System.Int32,System.Int32]] Zip[tblPrice,Int32,<>f__AnonymousType5
3](System.Collections.Generic.IEnumerable1[MyProjectMVC.Models.tblPrice], System.Collections.Generic.IEnumerable
1[System.Int32], System.Func3[MyProjectMVC.Models.tblPrice,System.Int32, <>f__AnonymousType5
3[System.Nullable`1[System.Decimal],System.Int32,System.Int32]])' method, and this method cannot be translated into a store expression.
Any help would be greatly appreciated.