【问题标题】:How do I use ."Include" on a Service Operation for ADO.Net Data Services如何在 ADO.Net 数据服务的服务操作中使用 ."Include"
【发布时间】:2009-07-23 10:04:10
【问题描述】:

我正在使用 ADO.Net 数据服务并有一个服务操作,最终将某些 linq 的结果返回到实体语句。作为这些 Linq 语句的一部分,有一个 .Include("NavProp") 来包含一个子对象。运行此服务操作时,它似乎不会返回扩展的包含。有谁知道这是为什么或如何解决?是否可以在对服务操作的调用中添加关键字来扩展该子对象? (我试过 $expand=subObject 但这似乎不起作用 - 错误的请求)。

我想最终得到: 1.) 服务操作中返回 .Include 的 linq 语句的语法(我很确定这是不可能的)

something like:
(from c in context.MyObj.Include("SubObj")
select c).ToList()
(this works inside the service operation, but doesn't provide the SubObj on the client side)

2.) 服务操作请求扩展子对象的语法

something like: http://localhost/MyDataService/MyDataService.svc/ServiceOp1?param1=234$expand=SubObj (note: this doesn't work)

【问题讨论】:

    标签: linq wcf-data-services service-operations


    【解决方案1】:

    目前看来这是不可能的(.net 3.5 SP1)。服务操作将只返回原始类型或实体。不能从服务操作返回任何其他类型,包括自定义类型或扩展实体。要处理这个问题,必须只从服务操作中返回项目,然后如果客户端需要包含/扩展,则必须调用“LoadProperty”以进行所需的对象扩展(注意:这意味着每个数据库都会命中另一个LoadProperty 调用)。

    【讨论】:

      【解决方案2】:

      已就此问题向 MS 发送电子邮件,解决方案是在服务操作的 uri 上使用扩展查询选项。例如,

      .../<ServiceOperationName>.svc?$expand=<Property1Name>,<Property2Name> ...
      
      Service Operation: GetCustomer
      Relationship Property to load: Address
      Uri: .../<GetCustomer>.svc?$expand=Address
      

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多