If I have a set of tables, TableA, TableB, TableC and TableD with TableA having one to many relationships with TableB, TableC and TableD.
Sometimes I want to return the entire set of TableA, TableB, TableC and TableD. Sometimes I want to return just TableA.
At the moment I have the following:
TableA tableA;
if (includeRelationships)
{
tableA = (from a in context.TableAs
.Include("TableBs")
.Include("TableCs")
.Include("TableDs")
where a.Id = myId
select a).SingleOrDefault();
}
else
{
tableA = (from a in context.TableAs
where a.Id = myId
select a).SingleOrDefault();
}
// do stuff with tableA
Is this the only way to do this?
EDIT - Clarification following feanz's answer:
This will be exposed as a WCF service so it needs to be a single DB call, either all tables or single TableA, so Lazy / Deferred Loading is not an option.