【问题标题】:AddQueryOption not working in WCF DataServices PortableAddQueryOption 在 WCF DataServices Portable 中不起作用
【发布时间】:2015-02-27 13:52:33
【问题描述】:

我创建了一个 Xamarin.Forms 项目,现在我打算使用 WCF 数据服务中的一些数据。

我这样创建查询:

        MyEntities entities = new MyEntities(new Uri("http://localhost/MyService.svc/"));
        DataServiceQuery<MyServiceReference.Info> query = entities.CreateQuery<MyServiceReference.Info>("GetInfo");            
        query.AddQueryOption("infoTag", "abc");
        query.BeginExecute((result) =>
        {
            try
            {
                var que = result.AsyncState as DataServiceQuery<MyServiceReference.Info>;
                var res = que.EndExecute(result);
                foreach (var item in res)
                {
                    System.Diagnostics.Debug.WriteLine(item.Name);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }, query);

根据this tutorial,我应该会看到完整的查询以及参数。

当我检查查询 URI 时,是这样的:http://localhost/MyService.svc/GetInfo

似乎缺少参数。

我怎样才能正确添加它们?

【问题讨论】:

    标签: c# wcf-data-services


    【解决方案1】:

    好吧,我想通了... 我非常喜欢 Fluent 语法,但我忘了检查 CreateQuery 是否使用它。

    所以不是

    query.AddQueryOption("infoTag", "abc");
    

    我必须使用这个:

     query=query.AddQueryOption("infoTag", "abc");
    

    或者这个:

    DataServiceQuery<MyServiceReference.Info> query = entities.CreateQuery<MyServiceReference.Info>("GetInfo").AddQueryOption("infoTag", "abc");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      相关资源
      最近更新 更多