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…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索