这是我的sql代码
SELECT M.PartNo AS ModulePartNo,
(SELECT SUM(Delivered - Allocated)
FROM V_InStock Stk
WHERE Stk.PartNo = M.PartNo) AS Available
FROM V_Products M
WHERE M.PartNo='100-25897'
我在Linq工作时遇到了真正的问题,无法解决这个问题 - 任何帮助都会非常感激
答案 0 :(得分:1)
这应该有用。
var query = from stk in V_InStock
group stk by stk.PartNo into stkg
where stkg.Key == '100-25897'
select new
{
ModulePartNo = stkg.Key,
Available = stkg.Sum(s => s.Delivered) - stkg.Sum(s => s.Allocated)
}
答案 1 :(得分:0)
如果你需要进行聚合分组等,你可能需要设置一个对象来“选择”所有内容。但是对于直接连接,这样的事情应该有效。
var outputObject = (from t1 in dbContext.table1
join t2 in dbContext.table2 on t1.PartNo equals t2.PartNo
select (t1.Delivered - t2.Allocated));