How to create a query expression for Odata to get by Id

I created the OData service, and now I'm trying to use this service on the client side. I want to create an expression, for example, for the bottom url in a C # query expression -

http://odata.org/Product-Service/Product (150)

The above url works fine in browsers, but I want to create a query expression in C # for the above url. Any help would be very noticeable.

+3
source share
1 answer

You can use DataServiceContext+ DataServiceQueryin System.Data.Services.Clientto get to Url. Remember that the request is not executed until First () is called due to lazy loading.

var context = new DataServiceContext(new Uri("http://odata.org/Product-Service"), DataServiceProtocolVersion.V3);
var query = context.CreateQuery<Product>("Product");
Product product = query.Where(p => p.Id == 150).First();

http://odata.org/Product-Service/Product (150), , query.Entities. Uri.

, Product , :

var query = context.CreateQuery<Product>("Product").
   AddQueryOption("$expand", "NavigationProperty");
+5

Source: https://habr.com/ru/post/1546715/


All Articles