So far as I gathered, LINQ to entities encourages eager loading with Load()
or Include()
. However, I wonder where should the eager loading take place in a multi-layered application?
Is it correct for the data-access layer (a repository class encapsulating the Entity instance) to have a generic Item GetItem(int id)
function, and in business logic layer do
Item item = dbRepository.GetItem(itemId);
if (!item.itemDetails.IsLoaded)
item.itemDetails.Load()
Or should the repository class have different explicit functions that load different foreign relations, therefore return Item of eager-loaded relations?
Many thanks!
Edit: Example - http://www.asp.net/learn/mvc/tutorial-29-cs.aspx
public Contact GetContact(int id)
This function returns a Contact
entity type. However, depends on the business logic needs, we may want to Load()
or Include()
different foreign relations of the Contact
entity. Does this requirement mean we need more overloaded GetContact()
methods with parameters indicating which relations to load, or simply do the Load()
in business logic?