First of all, I am using EF 6.0 using the Code First approach. My context configuration is set to Enable Proxy Creation and Lazy Loading.
My question is: Should lazy loading work with the results of a method that returns IEnumerable (and not IQueryable)?
I think the code below explains:
public void Test() { var company = GetCompanies().FirstOrDefault(); if (company.Employees.Count() > 0) {
Mark this comment, which I say: "I am here without errors!". This means that lazy loading works even after calling ToList (). I thought that after converting IQueryable to List or IEnumerable EF would lose the ability to do lazy loading.
I noticed that the proxy is still enabled for objects returned by the GetCompanies method (in debbug mode I see this ugly hash, for example: System.Data.Entity.DynamicProxies.Company_7035BEA374959AC1 ...).
Lazy loading works, even calling it in different DLLs. It's right? I mean, can another DLL make subsequent calls to my database, even if my method returns IEnumerable (and not IQueriable)?
Any clarification would be greatly appreciated.
c # entity-framework
fabriciorissetto
source share