c# - Azure 表 Controller - 通过参数获取记录

标签 c# azure xamarin.android azure-mobile-services

我正在开发一个 Azure 移动应用项目。我必须定义一个表 Controller ,它可以接受两个参数并给出值列表。我有一个 ProductItem 的 DataObject ,即

public class ProductItem : EntityData
{
    public string Name { get; set; }
    public string Details { get; set; }
    public double Price { get; set; }
    public string Image { get; set; }
    public Merchant Merchant { get; set; }
}

我需要获取特定的产品项目,并按其价格和商家进行过滤。已经在 ProductItemContoller ,我已经搭好了

// GET tables/ProductItem
public IQueryable<ProductItem> GetAllProductItems()
{
    return Query();
}

// GET tables/ProductItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
public SingleResult<ProductItem> GetProductItem(string id)
{
    return Lookup(id);
}

通过查看现有示例。但在示例中,我们没有从客户端调用任何给定的方法。相反,IEnumerable<ProductItem> items = await productTable.ToEnumerableAsync();被叫了。

我的问题是为什么我们不能调用 GetAllProductItems()它已经在客户端的 Controller 中定义了。如果我们可以打电话,该怎么做。

而且,我需要一个 Controller 方法,我需要一个 GetAllProductByMerchat(string merchantId) 。我怎样才能使这成为可能。

最佳答案

表 Controller 由客户端 SDK 代表您自动调用,允许您在客户端上使用 LINQ 查询。您可以使用类似以下内容:

var items = productTable.Where(p => p.Price < 100).ToListAsync();

这会通过网络转换为 OData 查询,然后转换回服务器上的 LINQ 查询,然后在服务器上转换为 SQL 并在 SQL Azure 实例上执行。

有关详细信息,请参阅 http://aka.ms/zumobook 的第 3 章

关于c# - Azure 表 Controller - 通过参数获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42465515/

相关文章:

android - Xamarin Android 应用程序在 Release模式下崩溃

c# - 如何创建单个 Web 应用程序作为许多公司的子域

c# - 如何在我的C#应用​​程序中使用系统音频输出绘制频谱

azure - 使用Microsoft Hive ODBC驱动程序在Azure文档数据库和HDInsight上的Hive集成方面的问题

azure - 通过 Azure CLI 配置 Blob 存储的日志记录

android - 在关闭应用的情况下调用 Xamarin.Forms 依赖服务

c# - 带有标记扩展名的字符串格式

Javascript 提示保存到 C# 中的变量,单击相同的按钮

caching - Azure 本地缓存与分布式缓存

c# - 如何将 Json 文件添加到 Xamarin 表单?