bradwestness / collate-dot-net

Filtering, sorting and paging extensions for .NET IQueryables
MIT License
21 stars 4 forks source link

Feature Request: FilterOpperation of EF.Functions.Like() #6

Closed JaronrH closed 5 years ago

JaronrH commented 5 years ago

I would like to request filter support for using using EF.Functions.Like(). For example: Contains -> context.DbSet.Where(x => EF.Functions.Like(x.Name, $"%{keyword}%")) Starts With-> context.DbSet.Where(x => EF.Functions.Like(x.Name, $"{keyword}%")) Ends With -> context.DbSet.Where(x => EF.Functions.Like(x.Name, $"%{keyword}"))

Thanks!

bradwestness commented 5 years ago

That would cause this library to need to take a direct dependency on Entity Framework, which it currently does not. Currently, the System.String methods for each of those filter operators are used (String.Contains, String.StartsWith, String.EndsWith) and it is up to the LINQ provider implemented by the underlying data source (EF in this case) to implement them appropriately.

I believe the way EF implements each of these is already exactly what you're proposing, where Contains "myValue" will wind up as like '%myValue%' in SQL, and StartsWith and EndsWith wind up as like 'myValue%' and like '%myValue', respectively. The screenshot in the README is evidence of this.

JaronrH commented 5 years ago

Thanks for looking into it. I can appreciate the desire to not have EF as a dependency.

FYI, I don't believe String.Contains, String.StartsWith, and String.EndsWith always turns into a SQL like statement. Ex: https://stackoverflow.com/questions/43277868/entity-framework-core-contains-is-case-sensitive-or-case-insensitive

bradwestness commented 5 years ago

Yeah, that's kind of the problem - different LINQ providers (EF Core vs EF 6.0, SQL Server vs PostgreSQL, etc) can implement those functions in different ways, and in order to handle each in a specific way, this library would need to handle each case specifically instead of letting the LINQ provider implement Contains() in whatever way is appropriate for the underlying data source.