Search code examples
c#linqodata

Odata and Select Issues


Have a OData Web Service that I want to query and apply conditional processing to but the following error is being recieved "Error translating Linq expression to URI: Can only specify query options (orderby, where, take, skip) after last navigation"

var reason = (from x in odataContainer.Table where x.userId == "test" select x.eventReason );
if (eventReason == "Failure")
      // Do something

The query does work if I don't make the selection specific i.e select x instead of x.eventReason however I want to avoid pulling back a lot of data by applying a filter.

Any suggestions on how to make this work?


Solution

  • Try this,

    var reason = odataContainer.Table.Where(x => x.UserId == "test").FirstOrDefault().eventReason;
    

    This should work!