Azure Table 控制器 - 通过参数获取记录
Azure Table Controllers - Get records by to parameters
我正在处理 Azure 移动应用程序项目。我必须定义一个 Table 控制器,它可以接受两个参数并给出一个值列表。我有一个 ProductItem
的数据对象,它是
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()
到客户端。如果可以调用,怎么调用。
而且,我需要一个控制器方法,我需要一个 GetAllProductByMerchat(string merchantId)
。我怎样才能做到这一点。
你是这个意思吗?
// Server method:
[HttpGet]
[Route("GetAllProductItems")]
public IQueryable<ProductItem> GetAllProductItems()
{
return Query();
}
// Client call
var result = await MobileService.InvokeApiAsync<IQueryable<ProductItem>>("ProductItem/GetAllProductItems", HttpMethod.Get, null);
记得在 ProductItemController 之前添加这些属性:
[MobileAppController]
[RoutePrefix("api/ProductItem")]
您可以对 GetAllProductByMerchat(string merchantId)
方法执行相同的操作。
Table 控制器由客户端 SDK 代表您自动调用,允许您在客户端上使用 LINQ 查询。您可以使用类似的东西:
var items = productTable.Where(p => p.Price < 100).ToListAsync();
这会通过线路转换为 OData 查询,然后在服务器上转换回 LINQ 查询,然后在服务器上转换为 SQL 并在 SQL Azure 实例上执行。
有关详细信息,请参阅 http://aka.ms/zumobook
的第 3 章
我正在处理 Azure 移动应用程序项目。我必须定义一个 Table 控制器,它可以接受两个参数并给出一个值列表。我有一个 ProductItem
的数据对象,它是
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()
到客户端。如果可以调用,怎么调用。
而且,我需要一个控制器方法,我需要一个 GetAllProductByMerchat(string merchantId)
。我怎样才能做到这一点。
你是这个意思吗?
// Server method:
[HttpGet]
[Route("GetAllProductItems")]
public IQueryable<ProductItem> GetAllProductItems()
{
return Query();
}
// Client call
var result = await MobileService.InvokeApiAsync<IQueryable<ProductItem>>("ProductItem/GetAllProductItems", HttpMethod.Get, null);
记得在 ProductItemController 之前添加这些属性:
[MobileAppController]
[RoutePrefix("api/ProductItem")]
您可以对 GetAllProductByMerchat(string merchantId)
方法执行相同的操作。
Table 控制器由客户端 SDK 代表您自动调用,允许您在客户端上使用 LINQ 查询。您可以使用类似的东西:
var items = productTable.Where(p => p.Price < 100).ToListAsync();
这会通过线路转换为 OData 查询,然后在服务器上转换回 LINQ 查询,然后在服务器上转换为 SQL 并在 SQL Azure 实例上执行。
有关详细信息,请参阅 http://aka.ms/zumobook
的第 3 章