Exactly from where I started.
Please take a look to the following (simple) example of what I need:
var q = db.From<LRARisultato>();
q.Join<LRAAnalisi>((ris, ana) => ana.Id == ris.AnalisiId);
q.Join<LRAAnalisi, LRAContenitore>((ana, con) => ana.ContenitoreId == con.Id);
q.Join<LRAContenitore, LRARichiesta>((con, ric) => ric.Id == con.RichiestaId);
q.Join<LRAAnalisi, LRDAnalisi>((ana, dana) => ana.AnalisiId == dana.Id);
q.LeftJoin<LRDRisultato>((ris, dris) => ris.RisultatoId == dris.Id);
q.Where<LRDRisultato, LRAAnalisi>((dris, ana) => dris.AnalisiId == 8 && ana.AnalisiId == 9);
q.Where<LRAContenitore, LRAAnalisi>((con, ana) => con.Stato == 0 && (con.RichiestaId == 1 || ana.Id == 2));
q.Or<LRAPaziente, LRARichiesta>((pat, ric) => pat.Id == 5550 || ric.Id == 7770 || ric.LaboratorioRichiedenteId == 222);
q.Where<LRAPaziente, LRAAnalisi>((pat, ana) => pat.Eta == 7 && ana.Id == 2);
this is the where statement
WHERE
((“LRDRISULTATI”.“DANALISIID” = @0) AND (“LRAANALISI”.“DANALISIID” = @1))
AND
((“LRACONTENITORI”.“STATO” = @2) AND ((“LRACONTENITORI”.“ARICHIESTAID” = @3) OR (“LRAANALISI”.“IDAANALISI” = @4)))
OR
(((“LRAPAZIENTI”.“IDAPAZIENTE” = @5) OR (“LRARICHIESTE”.“IDARICHIESTA” = @6)) OR (“LRARICHIESTE”.“DLABORATORIORICHIEDENTEID” = @7))
AND
((“LRAPAZIENTI”.“ETA” = @8) AND (“LRAANALISI”.“IDAANALISI” = @9))
where every Where<>, Or<> is a couple of ()
the first issue is about the number of table I need in each condition which is more than the 2 available
a tipical condition is something like
q.Where<POCO1, POCO2, POCO3…POCO10>((p1, p2…p10) =>
(
(p1.F1 == 1 && p2.F2 == 2) || ((p3.F3 == 2 || p4.F4 == 9) && p5.F5 == 5) && … p10.F10 == 10)
);
the second issue is about the nesting, I need to get something like
WHERE
((p1.F1 = @0) AND (p2.F2 = @1)) <- first group
AND
((p3.F3 = @2) AND ((p4.F4 = @3) OR (p5.F5 = @4))) <- second group
( <- notice Where<> inside external Where<>
OR
(((p6.F6 = @5) OR (p7.F7 = @6)) OR (p8.F8 = @7)) AND ((p9.F9 = @8) AND (p10.F10 = @9)) <- third group nested inside the second group
) <- end of internal Where<>
which I find out as something like
q.Where<p1, p2>()
q.Where<p3, p4, p5>().ThenOrBy<p6, p7, p8, p9>()
and so on using ThenAndBy