Need help: simplifying/changing a Oracle SQL-query, so I can use it in LINQ

66 Views Asked by At

I have following SQL-query and I have to build it up with LINQ, but it's too complex to find an easy way. :-/

Here is the query first:

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

I must tell you that "item.Id" and "type.Id" are parameters of type long, so you can replace them with a number.

Can someone help me to make an alternative query with same result, so I can use it with LINQ? Or can someone convert this directly to LINQ?!

0

There are 0 best solutions below