To add to Kamyar's answer...
The AllIncluding method is only available if you are using MVC scaffolding. see the following link for a listing of the method:
Mvc 3 Scaffolding: the Model passed to the View throws SQL errror
I tried using it, but still encountered the circular reference error, since the root objects were still being returned as proxies. So I customised the method to temporarily turn off the ProxyCreationEnabled flag on the EF context, and eagerly load the specified properties listed in the method's parameter. See the following link for further details:
Loading from database without proxy classes?
In order for this to work, the query had to be performed while the setting was still off, so I had to call the query's ToList() method to perform the query, and then returned the IEnumerable, rather than IQueryable. This did the job for me.
Here is the method I used ("_context" is the variable name for my EF context):
public IEnumerable ListIncluding(params Expression>[] includeProperties)
where TEntity : class
{
bool cachedSetting = _context.Configuration.ProxyCreationEnabled;
_context.Configuration.ProxyCreationEnabled = false;
IQueryable query = _context.Set();
foreach (var includeProperty in includeProperties)
{
query = query.Include(includeProperty);
}
IEnumerable list = query.ToList();
_context.Configuration.ProxyCreationEnabled = cachedSetting;
return list;
}
This can then get called using the following syntax:
IEnumerable newsItems = newsRepository.ListIncluding(news => news.Category, news => news.Image);