Skip to content
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

Case insensitive GroupBy() #351

Closed
kKen94 opened this issue Feb 21, 2020 · 7 comments
Closed

Case insensitive GroupBy() #351

kKen94 opened this issue Feb 21, 2020 · 7 comments
Labels

Comments

@kKen94
Copy link

kKen94 commented Feb 21, 2020

Is it possible adding IEqualityComparer to GroupBy()?

@StefH
Copy link
Collaborator

StefH commented Feb 22, 2020

Technically this is possible, however, what problem will this solve? Can you provide an example / unit test?

@kKen94
Copy link
Author

kKen94 commented Feb 24, 2020

var distinctedRaw = itemsToGroup  
                .AsQueryable()  
                .GroupBy($"new({string.Join(",", keys)})", "it")  
                .Select("it.First()")  
                .ToDynamicList<T>();

I use GroupBy() to group same values by dynamic keys and get unique values to remove duplicates.
But if I don't apply UpperCase(), "STRing"and "strING" for GroupBy are not the same and when I go to save data on database, the latter (obviously) crashes

@StefH
Copy link
Collaborator

StefH commented Feb 26, 2020

If you execute this query on a database (sql), then this does work fine.

In LinqPad:

string[] keys = new[] { "Text" };

var city = x.AsQueryable().Where(t => t.Text == "NewYork");
city.Dump();

var distinctedRaw = x
  .AsQueryable().Where(t => t.Text == "NewYork")
  .GroupBy($"new({string.Join(",", keys)})", "it")
  .Select("it.FirstOrDefault()");
  distinctedRaw.Dump();

image

@kKen94
Copy link
Author

kKen94 commented Feb 28, 2020

The problem is that i'm not querying db, i'm manipulating local array 😃

@StefH
Copy link
Collaborator

StefH commented Mar 2, 2020

I see.
It's possible to fix this, however it requires a lot of code changes in the GroupBy methods.

@kKen94
Copy link
Author

kKen94 commented Mar 2, 2020

... and a lot of time I suppose. This issue is not urgent, at the moment I lowercasing all. It's a bad workaround, I know, but otherwise I wouldn't know how to do it

@StefH StefH added the feature label Apr 3, 2020
@Lempireqc Lempireqc mentioned this issue May 26, 2020
@JonathanMagnan
Copy link
Member

Hello @kKen94 ,

The v1.1.2 has been released.

The GroupBy now supports the IEqualityComparer overload.

Best Regards,

Jon


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants