【问题标题】:Selecting multiple tables with DataServiceQuery使用 DataServiceQuery 选择多个表
【发布时间】:2013-03-25 11:24:35
【问题描述】:

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

私人 R.juliemrEntities 数据;

私有 DataServiceCollection 配方;

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

通过这个查询,我得到了食谱和它们的成分,但我无法扩展到第三个表,或者通过成分获取单位。

有谁知道我如何编写一个查询,让我同时掌握食谱、它们的成分和每种成分的单位?非常感谢您的帮助:)

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 像魅力一样工作!谢谢你:)
    【解决方案2】:

    如果您查看http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol 10.2.3.1.3 $expand 系统查询选项。您会发现 $expand=Ingredients/Unit 表示同时扩展成分和每种成分的单位。

    所以你只能使用一个展开

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

    【讨论】:

      猜你喜欢
      • 2014-02-11
      • 2011-12-17
      • 2015-07-10
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多