How to create a dynamic 'contains or LIKE' Expression to be used with Linq against OData service

不羁岁月 提交于 2019-12-05 12:16:56

OData currently doesn't support the "like" operator at all. So no matter what you do on the client, the URL produced has not way of expressing that. The substringof is supported and the client LINQ provider should generate it when you use string.Contains method in your filter (Where) expression.

To get the expression generated by a C# compiler you can do something like this:

IQueryable<string> source = new List<string>().AsQueryable();
IQueryable<string> result = from item in source where item.Contains("John") select item;
Console.WriteLine(result.Expression.ToString());

Basically any IQueryable has a property Expression which contains the expression tree for the query to run. Some LINQ providers might change the expression tree somewhat from the original one created by the compiler, but most should leave it close to the original.

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