Hi,I have this query ant I want to convert it to method syntax

from t in db.GS_POS_T
            join r in db.GS_POS_R on t.id_r equals r.id //it is inner join statement
            join c in db.GS_POS_C on t.id equals c.id_t  into ct
                  from sub1 in ct.DefaultIfEmpty()  //it is left join statement
            join p in db.GS_POS_PZ on sub1.id equals p.id_c into psub1
                  from sub2 in psub1.DefaultIfEmpty() //it is left join statement
                  where t.activ == 1
            select new { t.id, t.name, rname = r.name,  sub2.cant, sub2.price } into x
            group x by new { id = x.id, name = x.name, rname = x.rname } into g
            select new
                tid = g.Key.id,
                tname = g.Key.name,
                rname = g.Key.rname,
                sumpcantpprice = g.Sum(abc => abc.price * abc.cant)
I've tried something like this with luck:

                         c => c.ID,
                         p => p.ID_C,
                         (c, p) => new {
                             idc = c.ID,
                             idt = c.ID_t,
                             busy = p.Any() ? 1 : 0,
                             sum = Decimal.Round(p.Sum(pz => pz.PRICE * pz.CANT ?? 0M), 2)
                         m => m.ID,
                         c => c.idt,
                         (m, c) => new { c, m }
on last line I try to sort result by sum but on r=>r. I can't select child fields

Another problem is that in query 1 I want to include in final result ID field from db.GS_POS_C,but I got this error:

ExceptionMessage":"The cast to value type 'System.Int64' failed because the materialized value is null.
Either the result type's generic parameter or the query must use a nullable type."