GetAll with QueryOptions and IncludePaths Issue?

27 views
Skip to first unread message

todd....@gmail.com

unread,
Jun 9, 2016, 2:34:48 PM6/9/16
to SharpRepository
I'm experiencing some peculiar behavior with the following repository GetAll methods that involve query options:

- IEnumerable<T> GetAll(IQueryOptions<T> queryOptions, params Expression<Func<T, object>>[] includePaths);
- IEnumerable<T> GetAll(IQueryOptions<T> queryOptions, params string[] includePaths);

The association properties I specify to be included do not get loaded. However, if I use a method that does not take query options, the association properties are loaded.

IEnumerable<T> GetAll(params string[] includePaths); // This method works


My entities for clarity:

public class Widget
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Doodad> Doodads { get; set; }
}

public class Doodad
{
public int Id { get; set; }
public int WidgetId { get; set; }
public virtual Widget Widget { get; set; }
public string Name { get; set; }
}


I am using EntityFramework 6.1.3 for a datastore. I am injecting my repository as such:

IRepository<Widget, int> widgetRepo


And here's the code:

var pagingOptions = new PagingOptions<Widget>(pageNumber, pageSize, "Id");

var widgets = _widgetRepo.GetAll(pagingOptions, "Doodads"); //Doodads will be null

var widgets2 = _widgetRepo.GetAll(pagingOptions, x => x.Doodads); //Doodads will also be null

//and here is the really peculiar behavior - if I now invoke GetAll without query options, Doodads will be loaded on the widgets that I already got

_widgetRepo.GetAll("Doodads"); //Doodads on my widgets will now be loaded

Reply all
Reply to author
Forward
0 new messages