使用DataServiceQuery选择多个表

时间:2013-03-25 11:24:35

标签: c# asp.net windows-runtime wcf-data-services ado.net-entity-data-model

我正在使用WCF数据服务和ASP.NET主机,其中我有一个配方数据库的实体数据模型。实体“配方”连接到“成分”,其连接到“单位”。在我的客户端(Windows 8 RT应用程序)中,我正在尝试查询服务以获取配方的所有成分,以及与成分相关的单位。

私人R.juliemrEntities数据;

私有DataServiceCollection食谱;

var query =(DataServiceQuery)data.Recipes.Expand(“Ingredients”);

通过这个查询,我得到了食谱及其成分,但我无法扩展到第三个表,或通过成分获得单位。

有谁知道如何编写一个查询,让我能够掌握每种成分的配方,成分和单位?非常感谢帮助:))

2 个答案:

答案 0 :(得分:1)

对于“双扩展”,请使用类似的内容。第二次扩展调用包含一个类似于路径的字符串到第三个实体。

data.Recipes.Expand("Ingredients").Expand("Ingredients/Unit");

答案 1 :(得分:0)

如果查看http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol 10.2.3.1.3 $ expand系统查询选项。你会发现$ expand =成分/单位意味着扩展每种成分的成分和单位。

所以你只能使用一个展开

data.Recipes.Expand("Ingredients/Unit");