String.StartsWith not working with tilde (“~”) characters LINQ to SQL?

后端 未结 3 1429
眼角桃花
眼角桃花 2021-01-19 18:25

For some reason, my call to IEnumerable.Where() using String.StartsWith() appears to be giving different results depending on whether it\'s being used in LINQ-to-SQL or stan

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 19:07

    In the first case, indeed the Where predicate doesn't need to be translatable to SQL, since you are first getting the whole table to memory (ToList) and then doing the filtering.

    In the second case, the Where predicate needs to be translatable to a SQL WHERE clause, since the filtering is done in the database. TheString.StartsWith method is translated to a SQL LIKE statement.

    Remember that you can take a look at the generated SQL by using the DataContext.Log property. This should help you to understand how it works.

提交回复
热议问题