Reputation: 14586
I use Web API to return a Contrat EF Entity along with the metadata.
The Contract entity has a PersonId property which holds a foreign key to a Person entity. That's where things get complicated.
In order to get the Person entity, I need to make a call to a WCF service. This service does not retrieve the entity using entity framekwork. In fact, the Person entity is stored in an Oracle database.
Then on the client side, I need to assign that Person entity to the Contract Entity. I suppose I need to extend the Contract model and add a property of type Person.
I have been through the Edmunds sample, which seems close to what I'm trying to do.
I don't intend to call the WCF service directly from the client. Instead I'm going to make a call to a GetPerson method in my WEB API service, which in turn will make a call to the WCF service.
So, my question is: since I've got access to the Web API service, should I try to return a IQueryable along with metadata (sounds difficult to me), or should I simply return JSON data and go the Edmunds sample's way ?
Which is going to be easier to implement ?
Upvotes: 0
Views: 183
Reputation: 17863
The Edmunds example focuses on client-side queries to HTTP services that you do not control.
In this case, it sounds like you'd prefer to have everything happen on the server that you do control ... including any side-trips to a WCF service. That would be my preference too ... although I don't know the details that are necessary to make that judgment.
If I only need the related Person
when I fetch a single Contract
, I think I would have my Web API action method return a Contract
graph composed entirely on the server (including the Person
which I fetched on the server via the WCF Service).
But you may be thinking about the client who needs many Contract
entities - each expanded with related Person
entities - in a single call. Is this what you mean when you ask about putting IQueryable
on the method?
If so, I'd still consider composing these entirely on the server - with side-trips to get the related Person
objects - and then perhaps casting the resulting collection as an IQueryable
so that the client could filter. Ugh. I suspect that IQueryable
isn't wise; IEnumerable
is probably better. You can still pass some filtering values to the Web API method (see EntityQuery.withParameters
).
Upvotes: 1