Behaviour of string.Trim() in an Entity Framework query

北城以北 提交于 2019-12-04 15:27:44

The overall result should be the same. How are you profiling?

!context.Names.Any(n => n.Value == nameToCopy.Trim())

Above, the Linq to Entities .Trim() is converted to TSQL RTRIM(LTRIM()) and the string var is sent to SQL server in its original state and trimmed as part of the query.

string trimmedName = nameToCopy.Trim()
if (!context.Names.Any(n => n.Value == trimmedName)

Whereas above, the .Trim() is a normal System.String.Trim() and the string var is trimmed prior to sending to SQL Server.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!