Loading all the children entities with entity framework

前端 未结 3 2085
傲寒
傲寒 2020-12-03 05:02

I have a data model like this

\"Data

I would like to load all the related entities from a Recon

3条回答
  •  没有蜡笔的小新
    2020-12-03 05:38

    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.

提交回复
热议问题