EF iQueryable Linq不适用于十进制值比较
我在vs2012中使用EF 5。我正在使用DataContext并使用一些linq表达式在Iqueryable中搜索。我想找一个EF iQueryable Linq不适用于十进制值比较,linq,entity-framework,iqueryable,Linq,Entity Framework,Iqueryable,我在vs2012中使用EF 5。我正在使用DataContext并使用一些linq表达式在Iqueryable中搜索。我想找一个 var res= dbContext.Products.OrderBy(s => s.Id).AsQueryable(); if (startPrice > -1 && endPrice > -1 && (startPrice < endPrice)) { res = res.Where(s =>
var res= dbContext.Products.OrderBy(s => s.Id).AsQueryable();
if (startPrice > -1 && endPrice > -1 && (startPrice < endPrice))
{
res = res.Where(s => (s.UnitPrice >= startPrice && s.UnitPrice <= endPrice));
}
var list= res.ToList();
var res=dbContext.Products.OrderBy(s=>s.Id).AsQueryable();
如果(起始价格>-1&&endPrice>-1&&endPrice(起始价格 res=res.Where(s=>(s.UnitPrice>=startPrice&&s.UnitPrice这里我使用的是Northwnd样本数据库
decimal? startPrice = Convert.ToDecimal(400.5100);
decimal? endPrice = Convert.ToDecimal(500.5100);
var res = NDC.Orders.OrderBy(s => s.OrderID).AsQueryable();
if (startPrice > -1 && endPrice > -1 && (startPrice < endPrice))
{
res = res.Where(s => (s.Freight >= startPrice && s.Freight <= endPrice));
}
var l = res.ToList();
foreach (Order dcl in l)
{
Response.Write(dcl.Freight.ToString());
Response.Write("<br/>");
}
and result is
458.7800
477.9000
487.3800
411.8800
424.3000
487.5700
400.8100
decimal?startPrice=Convert.ToDecimal(400.5100);
十进制?最终价格=转换为十进制(500.5100);
var res=NDC.Orders.OrderBy(s=>s.OrderID).AsQueryable();
如果(起始价格>-1&&endPrice>-1&&endPrice(起始价格 res=res.Where(s=>(s.Freight>=startPrice&s.Freight)是否检查生成的SQL?是的。它添加了比较。但在运行时不工作。当我调用ToList()时方法您可以检查startPrice和endPrice是否正确吗?您可以检查硬编码值以进行测试。我已经厌倦了您的示例,它对我很好。是的,我已经检查了它们。它适用于不同的项目,但不适用于EF web API项目。在本例中,我的变量“res”是“System.Data.Entity.Infrastructure.DbQuery”键入。这是个问题吗?抱歉,伙计,问题解决了。我的数据库很大,调用toList()方法花费了将近10+分钟。现在绕过这个。无论如何,谢谢