Reputation: 61
I need to do a request on an OData service that would retrieve a single entity and that should look like this: /EntitySet(par1=value1,…,parn=valuen)
However, my LINQ generated query for fetching the entry looks like this: /EntitySet()?$filter=(par1 eq value1) and (par2 eq value2) and ... (parn eq valuen)
This is, of course, valid. But the server does not allow it. It only agrees with the first option, the one with the criteria in parentheses.
Is there something I can do? It would be a shame to manually create the query URL...
Here's the code:
var context = new CHART_SRV_Entities(oDataUri);
var query = context.ApplicationData.Where(ad =>
ad.institution == "1" &&
ad.patientId == "2000118" &&
ad.caseId == "2488");
DataServiceCollection<ApplicationData> data = new DataServiceCollection<ApplicationData>(context);
data.LoadCompleted += (s, args) =>
{
if (args.Error == null)
{
if (data.Continuation != null)
{
data.LoadNextPartialSetAsync();
}
else
{
var result = data;
}
}
else
{
MessageBox.Show(args.Error.Message);
}
};
data.LoadAsync(query);
Update: A "parentheses request" was achieved with CreateQuery here. However, that's a synchronous call. Any ideas on how to make it async?
Update2: Seems that what I'm trying to achieve is an OData composite key lookup. There's this OData library that can do it, but I find it hard to believe that this can't be done with the Microsoft toolset.
Upvotes: 5
Views: 1995
Reputation: 153
Only key properties are allowed to appear in the parentheses after the entity set name. If you are using non-key property to find the entry, you have to use the filter. This is how client works, and it is correct behavior.
In your case, I would suggest either customize client code or update the service code to support the filter, if you can.
Upvotes: 2