C
C#

help

GroupBy cannot be translated using

Kkaziux10/10/2022
Hello I can't for example group data by month using one of class datetime attribute navigation property month
var countryHolidays = await _db.Holidays
.Where(x => x.Country.CountryCode == countryCode && x.HolidayDate.Year == year)
.Include(x => x.Country)
.GroupBy(x => new {
Month = x.HolidayDate.Month
}).ToListAsync();
var countryHolidays = await _db.Holidays
.Where(x => x.Country.CountryCode == countryCode && x.HolidayDate.Year == year)
.Include(x => x.Country)
.GroupBy(x => new {
Month = x.HolidayDate.Month
}).ToListAsync();
ZZendist10/10/2022
Do you get an error?
Kkaziux10/10/2022
Yes. InvalidOperationException that query can't be translated https://www.inoaspect.com.au/entity-framework-core-ef-core-group-daily-data-to-monthly/ I was guided by this example
System.InvalidOperationException: The LINQ expression 'DbSet<Holiday>()
.Where(x => x.Country.CountryCode == __countryCode_0 && x.HolidayDate.Year == __year_1)
.Include(x => x.Country)
.GroupBy(x => new {
Month = x.HolidayDate.Month,
Year = x.HolidayDate.Year
})' 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'.
System.InvalidOperationException: The LINQ expression 'DbSet<Holiday>()
.Where(x => x.Country.CountryCode == __countryCode_0 && x.HolidayDate.Year == __year_1)
.Include(x => x.Country)
.GroupBy(x => new {
Month = x.HolidayDate.Month,
Year = x.HolidayDate.Year
})' 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'.
JJayy10/10/2022
that tutorial wont even load
var countryHolidays = await _db.Holidays
.Where(x => x.Country.CountryCode == countryCode && x.HolidayDate.Year == year)
.Include(x => x.Country)
.GroupBy(x => x.HolidayDate.Month)
.ToListAsync();
var countryHolidays = await _db.Holidays
.Where(x => x.Country.CountryCode == countryCode && x.HolidayDate.Year == year)
.Include(x => x.Country)
.GroupBy(x => x.HolidayDate.Month)
.ToListAsync();
try this @kaziux
Kkaziux10/11/2022
I did exactly the same way, but I get still the same exception
JJayy10/11/2022
try with Month.Name Or whatever Groupby is very finicky and i can't see ur entities
SSaber10/11/2022
you have to select something after grouping
Kkaziux10/11/2022
so may query order is bad? Impossible to use, because month itself is int property
JJayy10/11/2022
ahh, in that case ya try the select way that entity said i missed you didnt have one
SSaber10/11/2022
and if you are grouping purely to just group, not doing any aggregations you may just need to do that after the query is materialized
Kkaziux10/11/2022
I'm only do filtering query. No any agregrations like counting, average or something.
SSaber10/11/2022
grouping would have to be done on the c# side then after the query is completed as that doesn't make sense in sql
Kkaziux10/11/2022
I barely use grouping queries. I forgot that query is for aggregations

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Microsoft.Xaml.Behaviors.Wpf MouseMove event passing event args to command is passing nullI have wpf application view. It is capturing MouseMove event, which is sending MouseEventArgs as theEnvironmental Variables in VS 2022 [Answered]```js { "profiles": { "Library.Dependency": { "commandName": "Project", "environmeNeed help getting cest timezonei currently have this code ```cs var timer = new PeriodicTimer(TimeSpan.FromSeconds(1)); wHei all, I am new to this Server and I realy need help on specific Problem [Answered]I am trying to move a .csv File from a Folder to another and it is actualy working but when I open tHow to send multiple data sources to a view in asp.net 6? [Answered]Hey, So im learning asp.net 6. I have a page where i show products by giving a list to the view, ButUncaught Exception C++ hostfxr HandlingHi I have a C++ dll that I am using to host some dotnet assembly and normally things work but when sEntity Data Model WizardI was watching this tutorial: https://www.youtube.com/watch?v=1oGxPoTGl0U&ab_channel=TekTuition AroWhen to use EF queries, LinQ, or MySQLClientAttached is one of the Entity Framework (EF) queries I'm referring to (I'm not sure if this is what Process Checker [Answered]I'm creating an ""antivirus"" and I'm using a thread to check when a new process is started (but theArgumentNullException when argument is not nullI have this code: ```cs public class Config { [JsonProperty("token")] public string Token = "TOKWPF reusing the same template across multiple columnsThe following question https://social.msdn.microsoft.com/Forums/silverlight/en-US/f84e0efd-b1f2-4ab6Cascading DropDownI'm using MVC (.NET5) with EF and had this code to select a species on a View (to Create/Edit): ```cAssembly service findingHi, I am trying to find out if it's possible to get IServiceProvider, Microsoft IConfiguration or sohow do i submit a progra min vs to google classroomim trying to submit a project that's due to today but when i do submit it all i get is this and not WPF custom property not recognized by the compilerI have defined a custom property like below, it's in the namespace `CarApp`. It is supposed to repreEntity Framework DbContextOptionsBuilder.UseSqlServer() missing definitionI just installed the newest version of Entity Framework (6.0.9) and am inside my program.cs trying tDoes API manual nuget downloads come with the package dependencies?-WPF passing binding to a template from DataGridTemplateColumnSay, I have a template like this in resources, which I want to reuse for multiple columns, and whichBest way to implement a regex based lexer [Answered]In a regex lexer, you can loop over every pattern and do something like this: ```cs if (match.Successtring query in C Sharpi am trying to get values from 2 website links and assign them to a lable using visual studio one