0

我有以下 SQL 查询,我必须用 LINQ 构建它,但它太复杂了,找不到简单的方法。:-/

这是第一个查询:

SELECT * FROM tbl_a
LEFT JOIN
(
    SELECT tbl_a.id AS id
    SUM(tbl_b.amount) AS amount
    FROM (tbl_a LEFT JOIN tbl_c ON tbl_a.id = tbl_c.from_this_id)
        LEFT JOIN tbl_b ON tbl_c.id = tbl_b.tbl_c_id
        WHERE (tbl_c.deleted = FALSE)
               AND tbl_b.deleted = FALSE
               AND tbl_b.status = 2
        GROUP BY tbl_a.id
) tbl_tmp
ON tbl_a.id = tbl_tmp.id
WHERE (tbl_tmp.amount Is NULL OR tbl_a.amount > tbl_tmp.amount)
      AND tbl_a.amount > 0
      AND tbl_a.item_ID = item.Id
      AND tbl_a.type_ID = type.Id
      AND tbl_a.deleted = FALSE

我必须告诉你,“item.Id”和“type.Id”是long类型的参数,所以你可以用数字替换它们。

有人可以帮我做一个具有相同结果的替代查询,以便我可以将它与 LINQ 一起使用吗?或者有人可以直接将其转换为 LINQ 吗?!

4

0 回答 0