locked
Entity Framework and ToList() method RRS feed

  • Question

  • User1904516115 posted

    Does ToList() method affect the Entity Framework Lazy/Eager/Explicit Loading?

    Thursday, September 19, 2019 4:15 AM

All replies

  • User753101303 posted

    Hi,

    Something like var query=db.Items.Where(o=>o.Name.StartsWith("A")); just defines a query but doesn't run it. The query will run the first time you iterate on data using foreach or ToList...

    (if familiar with ADO.NET it could be compared with creating a SqlCommand and later executing this SqlCommand).

    So yes ToList is often used when you want to explicitely load data at this point rather than having the query being triggered later at the UI level for example...

    Thursday, September 19, 2019 8:37 AM
  • User-17257777 posted

    Hi vinodkpasi,

    As PatriceSc said, It is during the ToList() call when the query will actually be immediately executed. You can refer to Query Execution for further understanding.

    Best Regards,

    Jiadong Meng

    Friday, September 20, 2019 2:33 AM