开发者

Convert OData Uri to his equivalent Linq expression

开发者 https://www.devze.com 2023-02-25 10:14 出处:网络
I\'m creating a WCF service whose result is not a strict OData feed (for complicated reasons, business strategy, etc). In addition, the format of the URL is slightly different from OData although most

I'm creating a WCF service whose result is not a strict OData feed (for complicated reasons, business strategy, etc). In addition, the format of the URL is slightly different from OData although most of its features are very similar.

How I can tran开发者_C百科sform the URI in a Linq Expression tree?.

Thanks in advance.


Have a look at Linq2Rest - https://bitbucket.org/jjrdk/linq2rest. It parses an OData query into a LINQ expression, and the other way around. It's available on Nuget as well.


Currently this functionality is not exposed on its own. And writing it yourself is rather complex (depends on what type of queries you need to support and on your model). Is it really necessary to deviate from the OData protocol? Maybe what you need to do can be achieved through other means.


You can use following nuget package: https://www.nuget.org/packages/Community.OData.Linq

It allows to use OData text query parameters in linq expresson for any IQuerable without ASP.NET dependency

var result = query.OData().Filter("Id eq 1 or Name eq 'n3'").OrderBy("Name desc").ToArray();
0

精彩评论

暂无评论...
验证码 换一张
取 消