I am using Linq-To-Sql to populate my business layer. Here is a snippet of a query I am working on:
fund.FundEntities = fundGroup.tFunds
.Select(fe =>
{
var fundEntity = new FundEntity()
{
BankAccount = null,
CloseDate = fe.closeDate ?? new DateTime(),
Commitment = fe.commitment ?? 0,
CommitmentEndDate = fe.closeDate ?? new DateTime(),
Fund = fund
};
fundEntity.CapitalCalls = fe.tCapitalCalls
.Select(cc =>
{
return new CapitalCall()
{
Amount = cc.agrAmount ?? 0,
FundEntity = fundEntity
};
}
);
return fundEntity;
});
When I run this code, it executes queries for individual CapitalCalls at runtime. Is there anyway I could re-architect this to keep the same business object structure (IE- the relations from Fund -> FundEntity -> CapitalCall within the business objects), but load full tables at a time? Ideally, there would be a single SQL query with lots of joins that would result in a fully populated Fund.