How to create an Expression Tree to do something similar to the SQL “Like ” command

萝らか妹 提交于 2019-12-05 11:19:29

Expression trees can only represent the same sort of functionality as you get in .NET languages - method calls, property evaluation etc.

The closest you normally get to "like" is to call string.StartsWith, string.EndsWith or string.Contains. If you want to deal with regular expressions instead, you might want to use Regex.IsMatch instead. Either way, this is something which is encapsulated in methods rather than in the "language" of expression trees itself.

Without knowing more about how your expression trees are consumed, it's hard to say exactly what you should do. You could create your own "Like" method which the consumer would notice and handle appropriately, for example... or you could use the existing string/regex methods.

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