【问题标题】:How to Return All Rows in a Table of Azure Mobile Service .Net Backend如何返回 Azure 移动服务 .Net 后端表中的所有行
【发布时间】:2016-02-25 21:13:39
【问题描述】:

如何在没有 Where 子句的 Azure 移动服务 .Net 后端中获取表的所有行。这是我的尝试,但它不起作用。它说未定义的成员。

public async Task<List<Customer>> FetchAllCustomers()
       {
           var allCustomers = new List<Customer>();
           try
           {
               var list = await _customerTable.ToListAsync();
               foreach (var customer in list)
               {
                   allCustomers.Add(customer);
               }
           }
           catch (Exception e)
           {
               Log.Info(Tag, "Error fetching Customers" + e.Message);
           }

           return allCustomers;
}

如何重新编写这个简单的方法来获取 Azure 服务中客户表中的所有客户。我从 Xamarin.Android 客户端调用,并且已成功将项目添加到此表中。

【问题讨论】:

    标签: xamarin azure-mobile-services


    【解决方案1】:

    Carlos 已经在这里Azure Mobile Service query doesn't return all the rows回答了类似的问题

    我添加了名为 Active 的新字段,因此我可以应用 Where(active = Customer.Active);

    查询现在看起来像这样

    var list = await _customerTable.Take(100).Where(active => Customer.Active).ToListAsync();
    

    【讨论】:

      【解决方案2】:

      我的 Azure 表只返回了 50 条记录,但我知道还有更多记录。我将以下内容与 Xamarin C# 一起使用来查询表的总行数,然后使用行数获取所有记录,如果低于 1000 则使用 1000。请注意,计数查询使用 Take(0),因此不返回任何记录,只有总行数。

      IQueryResultEnumerable 的使用来自 Anzur Patel ITotalCountProvider 铸造错误 Xamarin 论坛。

      Azure Mobile Service query doesn't return all the rows 提供了仅获取 50 条记录的原因,以及如果总行数超过 1000 时我使用最大值 1000 的原因。

      How to get the row count from an azure database?提供了使用includeTotalCount()的方法。

      // query table to include the total row count
      var tableRowCount = (await _syncRecordTable.Take(0)
                         .Where (SyncRec => SyncRec.userid == sOwnerUniquCode )   
                         .IncludeTotalCount()
                         .ToEnumerableAsync());
      
      // get the row count
      long tCount = ((IQueryResultEnumerable<syncrecords>)tableRowCount).TotalCount;
      
      
      // convert long to int by casting
      int iCount = (int) tCount;
      
      if (iCount < 1000) {
          // get all records from the table
      _listCloudSyncRec = (await _syncRecordTable.Take(iCount)
              .Where (SyncRec => SyncRec.userid == sOwnerUniquCode)
              .ToListAsync ());
      }else {
      _listCloudSyncRec = (await _syncRecordTable.Take(1000)
              .Where (SyncRec => SyncRec.userid == sOwnerUniquCode )
              .ToListAsync ());
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多