Home > database >  is there a way to query OData with a linq query
is there a way to query OData with a linq query

Time:04-06

I'm using [EnableQuery] and returning an IQueryable from my api controller like this:

[HttpGet]
[EnableQuery]
public IQueryable<Category> Get()
{
    return getCategories().AsQueryable();
}

Is it possible to consume this odata url using linq, e.g. something like:

var res = await getOdata("Category").Where(item => item.Size > 100).ToArrayAsync();

does something like this exist ? I could only find examples of odata api's being built and consumed via string parameters but no linq.

CodePudding user response:

There are mainly 2 ways to add Query Options to a DataServiceQuery

  1. Using AddQueryOption method.
  2. Using strongly typed C# LINQ query methods.

So you can query OData with LINQ query. For more details, you can check below official doc.

LINQ Query Methods

  • Related