String.Equals() not working as intended

前端 未结 6 725
再見小時候
再見小時候 2020-11-28 10:49

I am using LINQ to search through one of my Entity Framework tables and find a \"group\" based on the name. The name is a string and appears to be Unicode (says it is in the

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 11:46

    The string comparison with StringComparison.OrdinalIgnoreCase works in memory or with IEnumerable. You are trying to use it with IQueryable, but the provider of your queryable does not understand it.

    This works for me:

    db.Users.FirstOrDefault(
         s => s.Username.Equals(username, StringComparison.OrdinalIgnoreCase)
    );
    

提交回复
热议问题