-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider fit the rule of AnonymousTypes for EFCore2.1? #165
Comments
So what you say is that is that in case of doing a |
Yes, |
|
Hi, has there been any movement on this? I'm seeing that groupBy isn't getting translated on ef core 2.1 |
@byrnedo It's not translated at all ? Or just not optimized as the first post from this issue describes? @yyjdelete I'll check the code to see if I can detect EFCore2.1 |
Sorry, meant that it says "could not be translated and will be evaluated locally".
This was from the following group by string:
I also happen to be doing a 'Sum' as well and that also gives the same warning. |
@StefH Do you have an idea of if or when optimisation of group by will be working? I'm evaluating alternatives since it's pretty important that it happens on the database side. |
I'm able to reproduce this issue with a sample console-app and I'll investigate. |
@byrnedo There is not really an easy way of detecting if EFCore 2.1 is used, so for now I'll just update the public bool EvaluateGroupByAtDatabase { get; set; } See linked checkin / branch for more details. |
//the the difference with sql
var key = 1;
var zz1 = ctx.Cars.Where(x => new { Id = x.Key } == new { Id = key }).ToList();
var zz2 = ctx.Cars.Where(x => new XX1{ Id = x.Key } == new XX1 { Id = key }).ToList();
var xx1 = ctx.Cars.Select(x => new { Id = x.Key }).GroupBy(x => x.Id).Select(x => new { Id = x.Key }).ToList();
var xx2 = ctx.Cars.Select(x => new XX1 { Id = x.Key }).GroupBy(x => x.Id).Select(x => new { Id = x.Key }).ToList(); |
|
@yyjdelete Can you help me with point 1 ? |
Issue 1 is updated. |
@StefH I would love to help out if it would speed this issue along. Any pointers on what I could do which would be helpful? |
Hello @byrnedo I did already start a new branch for this issue: And maybe I can create a PR, and you can continue on that ? (I'm not 100% if that will work in github?) |
@StefH Could I not fork and work on your branch and I can make a PR from that, and merge yours whenever/if you make changes? |
Also, is it possible to run the tests on dotnetcore only? |
Yes. You can use this branch. Tests should run for multiple frameworks... |
Got the tests to run. I've been looking around to see if there's anything you missed but honestly I can't see anything. |
@StefH could you go ahead and merge this? |
@byrnedo I'll double check the code now, and maybe implement this switch also in all |
Code will be merged. And new NuGet shortly... |
* EvaluateGroupByAtDatabase (#165) * wip * Added ParsingConfig.DefaultEFCore21 * Added EvaluateGroupByAtDatabase to Select and SelectMany
Thank you @StefH !! |
@StefH : Just had a look at this running in production:
The line that does the group by looks as follows:
ParserConfig has the GroupByAtDatabase set to true. |
Hello @byrnedo, Can you also reproduce this same issue in this example app ? |
Hey @StefH ! Yeah, just managed to recreate it now. I added a It seems to happen if I do a join and project the result like this:
It works if the projection was like this:
Is this something that a custom type provider would solve? EDIT: Also doesn't translate if I project to a user defined class
EDIT 2: I guess this mightn't have anything to do with this library and more to do with what efcore supports? |
I've opened an issue with efcore as well: dotnet/efcore#13077 |
For this, @byrnedo In efcore, any expression maybe evaluated locally, and for compatibility, efcore keeps most behavior as clr does. But in clr, you can write an class like the below(and public class Xx
{
public int Yy
{
get => 1;//<-Not return the same with setter
set { }
}
public override bool Equals(object obj)
{
return false;//<-No Equals or Equals not compare the properties
}
public override int GetHashCode()
{
return -1;
}
} |
The |
Ok so as I've understood, no fix in this project will get around my use case and the limitation is by design in efcore? Edit: @yyjdelete was this the issue you were talking about? |
Also commented on #199 @byrnedo and @yyjdelete With code fixed (see linked example here https://github.com/StefH/System.Linq.Dynamic.Core/blob/EvaluateGroupByAtDatabase/src-console/ConsoleAppEF2.1/Program.cs), the sql statement is correct: SELECT [c].[Key], [c].[Brand], [c].[Color], [c].[Vin], [c].[Year], [inner].[BrandType], [inner].[BrandName]
FROM [Cars] AS [c]
INNER JOIN [Brands] AS [inner] ON [c].[Brand] = [inner].[BrandType]
ORDER BY [c].[Year] |
@StefH I wasn't very clear in the recreation post above. The code I'm running locally was translating the Join before, just not the subsequent GroupBy expression. |
@byrnedo Maybe it's a best idea to just add the |
I'd say it might be ok without. This case of mine is by design as @yyjdelete suspected and confirmed now in dotnet/efcore#13077, so really I think this issue could be closed again. |
Closing this one. |
EFCore2.1(in rc1 stage currently) add an new ability to do LINQ GroupBy translation, but only works with basic types, anonymous types and Tuple(with ctor).
But by default,
System.Linq.Dynamic.Core
useLinqProviderExtensions.IsLinqToObjects(IQueryable)
to getcreateParameterCtor
(which is false for EFCore), and there is no way to change that. And then the expression can not be recognized by EFCore as AnonymousTypes, and will be evaluated locally.vs
The text was updated successfully, but these errors were encountered: