我正在尝试在 LINQ 上执行此操作:
select p.ProductID, p.ArticleCode, SUM((case h.OperationType when 0 then 1 else -1 end) * h.[Count])
from Products p
inner join StockItems s on p.ArticleCode = s.ArticleCode
inner join StockHistorical h on s.ArticleID = h.ArticleID
where h.[Date] < '23/08/2013 11:30:00'
group by p.ProductID, p.ArticleCode
我有这个:
var products = (from p in e.Products
join s in e.StockItems on p.ArticleCode equals s.ArticleCode
join h in e.StockHistoricals on s.ArticleID equals h.ArticleID
where h.Date < DateTime.Parse("23/08/2013 11:30:00")
group p by p.ProductID into StockResult
select new { });
任何人都知道我该怎么做
SUM((case h.OperationType when 0 then 1 else -1 end) * h.[Count])
与 LINQ?
谢谢!
我忘了说问题是“分组依据”,因为我无法访问 StockResult 组中的 OperationType 属性。
解决了!关键是:
let combined = new
{
Product = p,
HistoryCount = (h.OperationType == 0 ? 1 : -1) * h.Count
}