I have a data model like this
I would like to load all the related entities from a Recon
There are two ways to perform Eager Loading in Entity Framework:
There are also manners to write Raw SQL Queries against database:
For the case, when you're attempting to load nearly entire database, it would be good idea to execute dedicated store procedure against it.
Try with just .Include(r => r.ReconciliationDetails)
initially. Then add the .Select()
statements one-by-one. At what point does the exception reappear? The .SelectMany()
call looks a bit suspicious to me!
A second question that might help identify the problem... After you run the code that contains all the ToList()
calls, is your recon
entity complete? i.e. are all its navigation properties populated? This should be the case because of the automatic 'fixup' behavior of Entity Framework.
With EF, sometimes it is more efficient to load a complex object graph with several calls rather than chained Include()
calls. Check the generated SQL and see what is most efficient in your case.
Not sure if it's to late but could you benefit from structuring your code such as
var acctName = "someName";
var detailList = _repository.Include(e => e.JrnlEntryDetail).Filter(c => c.JrnlEntryDetail.Any(e => e.AcctName == acctName)).Get().ToList();