-
-
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
Question: Is it possible to do case-insensitive search #128
Comments
This is related to your SQL-server settings ? |
@rajeshmuraleedharan When you install SQL Server you must specify the collation. CI is for case insensitive and AI is for accent insensitive. Anyway, It could be great to make requests in CI, AI, CS or AS "on demand". |
I think, you should able to use: |
@jogibear9988 This will not work for this library I think. |
Sadly it doesn't work, the part "StringComparison" is treated as a property and you get an error saying, that the property or field 'StringComparison' exists in the currently used type.
Works perfectly for me :-) |
How do you do a case sensitive search with this library ??? Query.Where($"{dataPropertie.Name}.ToString().Trim().ToLower().Contains(@0)", cols.Values.ToStringNullSafe().Trim().ToLower()).OrderBy(dataPropertie.Name).ToList(); I tried something like this but is not working |
@rajeshmuraleedharan With #450,
@wilari932 How would you write a case-insensitive search using standard expression trees? If this would work:
then the following should also work:
|
Still does not work for me in 1.2.6: |
@khmurach How are you escaping the quotation marks? Also, is this being run against a database or other Queryable provider? |
Yes, I'm escaping. I'm using Where on List().AsQueryable() |
@khmurach This works for me: var lst = new List<User>();
var qry = lst.AsQueryable().Where("GivenName.Contains(\"sa\", StringComparison.OrdinalIgnoreCase)");
public class User {
public string? GivenName { get; set; }
} Visualizing |
@zspitz I have generic method so there is no properties to use in standard Where(x=>x.Name.Contains("value")).
This line works fine: |
targetFramework="net451" |
@khmurach It seems that .NET Framework 4.5.1 doesn't support this overload of N.B. The IQueryable<T> ApplyFilter(IQueryable<T> dataAll, Func<T, bool> filter) {
} and then you would have strong-typing on the filter itself. Although I don't quite see what it gives you over the standard |
Even in this simplified example, first two queries works fine but the last one throws error:
|
I'm using
|
Any updates on how to do an case invariant search? |
I'm also having this problem with Contains with the System.Linq.Dynamic.Core package at version 1.2.18, but only when running my actual code. If I run Unit tests everything works perfectly. [Fact]
public void DynamicLinq_SingleContains_SimpleText_CaseInsensitiveOverload()
{
var filter = "(Name != null && Name.Contains(\"Blu\", StringComparison.CurrentCultureIgnoreCase))";
var data = GetDynamicLinqTestData().AsQueryable();
var filteredData = data.Where(filter).ToArray();
Assert.Single(filteredData);
}
[Fact]
public void DynamicLinq_SingleContains_ReplacementText_CaseInsensitiveOverload()
{
var filter = "(Name != null && Name.Contains(@0, StringComparison.CurrentCultureIgnoreCase))";
var filterParams = new List<object>();
filterParams.Add("Blu");
var data = GetDynamicLinqTestData().AsQueryable();
var filteredData = data.Where(filter, filterParams.ToArray()).ToArray();
Assert.Single(filteredData);
} Both of these tests work fine in XUnit. But when I run my code that creates the exact same thing (either way, and I have unit tests on those create functions too) I get I've tried also using the older method of doing just an escaped string of the enum like "CurrentCultureIgnoreCase" but that doesn't work either. Doesn't matter which enum I use, OrdinalIgnoreCase doesn't work either. It does appear to work if I let it be case sensitive, but that's not ideal. I just don't understand why it works in unit tests and not in practice. I will also note that string.StartsWith and EndsWith both DO work in unit tests and in practice using the case sensitive enums. Which is even weirder. Update:
|
Closing.. |
I would like to do case-insensitive search with startswith,endwith and Contains. Please let me know this is possible or not.
The text was updated successfully, but these errors were encountered: