During my CQRS journey, I implemented many-to-many data querying, in the single database request. I achieved getting all products with associated entities at the same time.
To achieve the same, we need to define a temporary table to store all first-level entities:
CREATE TABLE #Products ( Id int, Name NVarchar(128), Price decimal ) Then insert first-level entities into this table:
INSERT INTO #Products SELECT P.Id, P.Name, P.Price FROM dbo.Products AS P ORDER BY P.