Entity Framework Core case-sensitive processing
Entity Framework Core case-sensitive processing Can ‘StringComparison’ be used? In the database query operation, it is inevitable to consider the issue of letter case. For example, if you want to search for the movie “X-Men” in the Movie table, in order not to distinguish between letter case and case, according to the habit of Linq to memory, you may Will write the following code: DbContext.DbSet .Where(item => string.Equals(item.Title, “X-Men”, StringComparison.InvariantCultureIgnoreCase) However, an error will be reported when the above code is executed, indicating that the ‘StringComparison’ parameter is not supported. InvalidOperationException: The LINQ expression ‘DbSet() .Where(m => string.Equals( a: m.Genre, b: __MovieGenre_0, comparisonType: InvariantCultureIgnoreCase))’ could not be translated. Additional information: Translation of the ‘string.Equals’ overload with a ‘StringComparison’ parameter is not supported. See https://go.microsoft.com/fwlink/?linkid=2129535 for more information. 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’. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information. How to solve this problem? If you are using SQL server or MySQL, it is very simple, just remove the “StringComparison.InvariantCultureIgnoreCase” parameter, because they are case-insensitive by default. If you are using a case-sensitive database, such as PostgreSQL, you need to…