خرید بک لینک

Vote count: 0

Typical, one User (happens to be .NET Identity ApplicationUser) to many Sale relationship, and I'm trying to produce a list of top ten salespeople. I also need the current user's rank in said list (regardless of whether it's in the top ten) e.g.

User1   $10.00
User2   $8.50
User3   $7.00

hence, using Select's overload that includes the index

My current LINQ query is raising a horrifically hard to read error about not recognizing a method--I think the Select method:

var sales = this.Context.Sales
    .GroupBy(x => x.User) // ApplicationUser
    .Select((x, index) => new UserSale
    {
        UserId = x.Key.Id,
        Useame = x.Key.UserName,
        SalesTotal = x.Sum(y => y.Price),
        Rank = index,
    })
    .OrderByDescending(x => x.SalesTotal);

vm.SalesRank = sales.Single(x => x.UserId == this.UserContext.Id).Rank;

vm.Sales = sales.Take(10).ToList();

where UserSale is a POCO like this:

public class UserSale
{
    public string UserId { get; set; }
    public string Useame { get; set; }
    public decimal SalesTotal { get; set; }
    public int Rank { get; set; }
}

And the error is tough for me to even decipher:

LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[MyApp.Models.UserSale] Select[IGrouping`2,UserSale](System.Linq.IQueryable`1[System.Linq.IGrouping`2[MyApp.Models.ApplicationUser,MyApp.Models.Sale]], System.Linq.Expressions.Expression`1[System.Func`3[System.Linq.IGrouping`2[MyApp.Models.ApplicationUser,MyApp.Models.Sale],System.Int32,MyApp.Models.UserSale]])' method, and this method caot be translated into a store expression.

I've been reviewing the various overloads of GroupBy for awhile, and I'm pretty sure this is the one I want. What else am I missing?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 8 خرداد 1395 ساعت: 7:57

صفحه بندی