使用 Linq Sql 加入通用处理程序
Using Linq to Sql join in generic handler
我有一些查询可以正常工作,但我只是复制了准确的代码而没有对新的通用处理程序 (ashx) 文件进行任何修改,但出现了错误。这是代码:
System.Collections.Generic.List<ChartPrice> ChartPrices =
new System.Collections.Generic.List<ChartPrice>();
using (DatabaseDataContext db = new DatabaseDataContext())
{
ChartPrices = (from p1 in db.Prices
join p2 in db.Prices on p1.Date equals p2.Date
where p1.ProductId == -1 && p1.Id != p2.Id
orderby p1.Date descending
select new ChartPrice {
Price1 = p1.Amount.ToString(),
Price2 = p2.Amount.ToString(),
Date = (DateTime)p1.Date })
.Take(30).ToList();
}
这是错误:
Error 33 Could not find an implementation of the query pattern for source type 'System.Data.Linq.Table'. 'Join' not found. Are you missing a reference or a using directive for 'System.Linq'?
我在第一个 db.Prices (ChartPrices = (from p1 in db.Prices
)
下得到一条红线
我可以做些什么来在通用处理程序文件中使用此代码吗?
基础 class 不 include/use System.Linq
因此 linq 表达式不适用于代码。
注意:这个问题在评论中已经解决了,这个答案只是给那些没有看评论的人。
我有一些查询可以正常工作,但我只是复制了准确的代码而没有对新的通用处理程序 (ashx) 文件进行任何修改,但出现了错误。这是代码:
System.Collections.Generic.List<ChartPrice> ChartPrices =
new System.Collections.Generic.List<ChartPrice>();
using (DatabaseDataContext db = new DatabaseDataContext())
{
ChartPrices = (from p1 in db.Prices
join p2 in db.Prices on p1.Date equals p2.Date
where p1.ProductId == -1 && p1.Id != p2.Id
orderby p1.Date descending
select new ChartPrice {
Price1 = p1.Amount.ToString(),
Price2 = p2.Amount.ToString(),
Date = (DateTime)p1.Date })
.Take(30).ToList();
}
这是错误:
Error 33 Could not find an implementation of the query pattern for source type 'System.Data.Linq.Table'. 'Join' not found. Are you missing a reference or a using directive for 'System.Linq'?
我在第一个 db.Prices (ChartPrices = (from p1 in db.Prices
)
我可以做些什么来在通用处理程序文件中使用此代码吗?
基础 class 不 include/use System.Linq
因此 linq 表达式不适用于代码。
注意:这个问题在评论中已经解决了,这个答案只是给那些没有看评论的人。