String Comparison exception within Entity Framework FirstOrDefault

后端 未结 1 1416
攒了一身酷
攒了一身酷 2021-01-18 23:39

I\'m querying a table using Entity Framework. The first bit of code was what I wrote, the second bit was what ReSharper suggested I refactor it too. The first one gracefully

1条回答
  •  再見小時候
    2021-01-19 00:08

    So my question is: what is the difference between the two expressions?

    The diffence is that the later is using the CLR String.Equals Method (String, String, StringComparison) which is not supported by EF according to CLR Method to Canonical Function Mapping while all the methods used in the former (string.ToLower and string equality operator) are supported.

    In general you cannot control the string comparisons for EF queries from code because they are controlled by the database.

    0 讨论(0)
提交回复
热议问题