Row_number over (section on yyy) in Linq?

I am very new to LINQ, and one of my first attempts to use it was difficult!

I am trying to adapt the accepted answer in this Stack Over question .

I wrote it like this:

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);
            }

        }

In principle, I want to return the cheapest price for the same goods from different suppliers.

However, when I run the project, I get the following very long error message, and I have no idea what this means. But it looks pretty serious!

LINQ to Entities "System.Collections.Generic.IEnumerable 1[<>f__AnonymousType5 3 [System.Nullable 1[System.Decimal], System.Int32,System.Int32]] Zip[tblPrice,Int32,<>f__AnonymousType5 3] (System.Collections.Generic.IEnumerable 1[MyProjectMVC.Models.tblPrice], System.Collections.Generic.IEnumerable 1 [System.Int32], System.Func 3[MyProjectMVC.Models.tblPrice,System.Int32, <>f__AnonymousType5 3 [System.Nullable`1 [System.Decimal], System.Int32, System.Int32]])" , .

.

+3
1

@ , , LINQ SQL.

, :

  • MS SQL LINQ
  • ows SQL
  • @Matt Burland - ,

, :

var q = ctx.tblPrices.OrderByDescending(x => x.Cost)
                .ToList()
                .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}));

:

var q = ctx.tblPrices.OrderByDescending(x => x.Cost)
                .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.WebPrice, j.PriceID, j.ItemID}));

.

+4

All Articles