你好,我在我的MVC4 WebApi应用程序中有一个实体模型ProdcutTable,它有以下列名
[ProductID] [ProductName] [ProductDescritpion] [Price] [ImageURL] and so on现在,我必须将价格范围作为参数进行传递
frstvale=$200
SecoundVal=$500我必须从所选价格范围的ProdcutTable中检索ProductID ProductDescritpion ImageURL我如何为此编写linq查询目前我正通过ajax调用从表中检索所有图像现在我必须将价格的参数传递给我的方法并检索所选价格范围的记录任何人都可以帮助编写此查询
this is my model
public class Products
{
public int ProductID { get; set; }
public string ProductName{get;set;}
public string ProductDescription { get; set; }
public string ProductColor { get; set;}
public string ProductSize { get; set; }
public string Brand { get; set; }
public int Price { get; set; }
public string Department { get; set; }
public string ImageURL { get; set; }
public string DetailsURL { get; set; }
public string Gender { get; set; }
public string Firstvalue { get; set; }
public string Lastvalue { get; set; }
}这就是我检索所有图像的方式
private ProductsEntities products = new ProductsEntities();
public IEnumerable<ProductTable> GetAllProdcuts()
{
return products.ProductTables.AsEnumerable();
}发布于 2012-09-14 15:11:37
您可以使用以表达式为参数的Where扩展方法来过滤出返回的对象。
private ProductsEntities products = new ProductsEntities();
public IEnumerable<ProductTable> GetAllProdcuts()
{
return products.ProductTables.Where(x=>x.Price>firstPrice && x.Price<secondPrice).AsEnumerable();
}https://stackoverflow.com/questions/12419684
复制相似问题