我正在开发一个 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/