0

我使用 Web API 返回一个Contrat EF 实体以及元数据。

Contract实体有一个 PersonId 属性,它持有一个Person实体的外键。这就是事情变得复杂的地方。

为了获取Person实体,我需要调用 WCF 服务。此服务不使用实体框架检索实体。实际上,Person实体存储在 Oracle 数据库中。

然后在客户端,我需要将该人员实体分配给合同实体。我想我需要扩展Contract模型并添加Person类型的属性。

我已经通过了 Edmunds 样本,这似乎与我想要做的很接近。

我不打算直接从客户端调用 WCF 服务。相反,我将调用我的 WEB API 服务中的 GetPerson 方法,该方法又会调用 WCF 服务。

所以,我的问题是:既然我可以访问 Web API 服务,我应该尝试返回一个 IQueryable 以及元数据(对我来说听起来很难),还是应该简单地返回 JSON 数据并采用 Edmunds 示例的方式?

哪个更容易实施?

4

1 回答 1

1

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).

于 2013-04-30T21:02:54.297 回答