C
C#2y ago
Dreams

❔ Help with EF Core Linq statement

GitHub
Frizerski-Salon-ML/DynamicContentController.cs at main · dzenis-zig...
Contribute to dzenis-zigo/Frizerski-Salon-ML development by creating an account on GitHub.
11 Replies
Angius
Angius2y ago
Like this: .OrderByDescending(x => x.OrderIndex) Seems you already have it
Dreams
DreamsOP2y ago
ok so my table is Unique Id | Not Unique Name | OrderIndex I want to return data so that all the non-unique Name rows are next to eachother
Angius
Angius2y ago
What do you mean "next to eachother"?
Dreams
DreamsOP2y ago
well ToLookup puts identical Names in their own array
Angius
Angius2y ago
Ah, so it groups the entries by the names? Never in my life have I used .ToLookup() .GroupBy() if anything So, that explains why nothing gets sorted You sort the entries first, then you group them
Dreams
DreamsOP2y ago
oh interesting
Angius
Angius2y ago
Do you want entries within each group to be sorted? Or do you want groups themselves to be sorted somehow?
Dreams
DreamsOP2y ago
System.InvalidOperationException: The LINQ expression 'DbSet<DynamicContent>()
.OrderByDescending(x => x.OrderIndex)
.Select(d => new DynamicContentDTO(d))
.GroupBy(x => x.Name)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
System.InvalidOperationException: The LINQ expression 'DbSet<DynamicContent>()
.OrderByDescending(x => x.OrderIndex)
.Select(d => new DynamicContentDTO(d))
.GroupBy(x => x.Name)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
var dynContentList = await _context.DynamicContents
.OrderByDescending(x => x.OrderIndex)
.Select(d => new DynamicContentDTO(d))
.GroupBy(x => x.Name)
.ToListAsync();
var dynContentList = await _context.DynamicContents
.OrderByDescending(x => x.OrderIndex)
.Select(d => new DynamicContentDTO(d))
.GroupBy(x => x.Name)
.ToListAsync();
Angius
Angius2y ago
Huh, right, grouping might not translate well I guess if you're fetching everything regardless, might as well do the grouping on the client
Dreams
DreamsOP2y ago
i see sorting first then grouping makes sense thank you @Angius i learned something
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server