1

I'm about to implement a web service for my database, perhaps using WCF Data Services. Some of the objects I need to make available have child objects that need to be present for the objects to be useful. But because of lazy loading in the Entity Framework, those child objects are not going to be automatically loaded.

I'm going to be calling this service using JSON, and I don't want to have to specify the $expand option in each call. And it's not clear to me where I would use the LoadProperty method (same link), since I'm just writing the InitializeService method and letting the framework do the rest.

Is there a way to configure it to explicitly load some child objects and not others?

4

2 回答 2

1

WCF 数据服务当前不支持服务器上的自动扩展。客户总是不得不要求扩展。

通过修改传入的请求,您可以围绕 WCF DS 实施某种解决方法。因此,例如,如果客户端发送对 ~/Products 的请求,您可以在它到达 WCF DS 之前对其进行修改并让它处理 ~/Products&$expand=Category,这样可以有效地实现自动扩展。但是要使这样的服务变得健壮,您必须解析查询 URL,并且只有在其中还没有扩展时才添加扩展,依此类推。

于 2012-07-09T16:58:00.660 回答
0

另一种方法是,如果子对象总是需要存在,我们可以使子对象复杂类型而不是实体,以便它们始终与父对象一起出现。子对象是单个实体是否有充分的理由?

希望这可以帮助。

谢谢普拉蒂克

于 2012-07-09T17:19:51.263 回答