Skip to content

Instantly share code, notes, and snippets.

@mesuttalebi
Created February 25, 2015 14:11
Show Gist options
  • Save mesuttalebi/74338be98279d3ca1b21 to your computer and use it in GitHub Desktop.
Save mesuttalebi/74338be98279d3ca1b21 to your computer and use it in GitHub Desktop.
Entity Framework Eager loading data with selective properties. A dynamic way to add context.entities.Include(x=> x.propery1).Include(x=> x.property2)....
public IQueryable<Entity> GetAllIncluding(params Expression<Func<Entity, object>>[] includedProperties)
{
IQueryable<Entity> query = db.Groups;
foreach (var includedProperty in includedProperties)
{
query = query.Include(includedProperty);
}
return query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment