score:2
Accepted answer
Is this linq-to-entities? Then it is not possible to do any kind of filtering to the included entities that are eager loaded. Ladislav Mrnka wrote about it in his latest blog post.
It is of course possible to use linq-to-objects to handle the entities once loaded into memory, but if you only want a fraction of the available entities that would be inefficient.
A linq-to-objects solution:
var userGroups = this.ObjectContext.UserGroups.Include("Users")
.Select(ug => new UserGroup {
Name = ug.Name,
// Copy all fields
Users = ug.Users.Where(u => u.Active)
});
score:1
Could you reverse the statement to be
var userGroups = this.ObjectContext.Users.Include("UserGroups").Where(f=>f.IsActive == true);
And then use a GroupBy on the UserGroups field?
Source: stackoverflow.com
Related Articles
- LINQ to filter included entity
- LINQ Source Code Available
- Entity Framework Core LINQ Class Property/Methods can't use Included Property
- creating Linq to sqlite dbml from DbLinq source code
- EF Core LINQ exclude column from included entity
- SQL subquery result in LINQ and Entity Framework Code First
- How to filter related data using Entity Framework and LINQ to SQL and LinqKit PredicateBuilder Or IdeaBlade DevForce
- Filter rows before .ToList() using LINQ and Entity Framework
- LINQ entity data model generated code error - The type 'DBContexts.Category' already contains a definition for 'ID'
- C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent
- source code for LINQ 101 samples
- How to Filter Child Collection from each Parent Entity in the Parent Collection using Linq
- Filter list of entity objects by string child object property using Linq Lambda
- Creating a dynamic EF filter that builds a LINQ Where equals/contains statement for any string entity property
- how to select data by linq in many-to-many relationship in First code Entity framework 5
- Linq to Entity Filter using Navigation Property
- LINQ - Entity framework code first - Grouped results to custom class
- Linq to Entity : add filter to child entities of child entities
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- How can I select from an included entity in LINQ and get a flat list similar to a SQL Join would give?
- Entity Framework - Filter LINQ by ICollection type using TPH
- Simple linq question: How to filter a source afterwards?
- Entity Framework 4 and Linq to Entities specifications: How to code it?
- c# Linq or code to extract groups from a single list of source data
- Getting InvalidCastException when trying to implement sorting in Entity Framework Code First using Linq
- Linq Find Partial Text Match - Included code returns duplicate and everything except what it should
- c# WPF bind combobox to TPH in Entity Framework code first using LINQ
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Completing a linq to entites query of a tri-level entity source
- How to Filter DataGridView when bound to a linq query result that is linked to an EF4 Entity
- How Select All Record From DataTable Distinct By Only One Column
- How to get an overloaded == operator to work with LINQ and EF Core?
- LINQ ToList() serialization error?
- For loop to linq
- Using a variable for a LINQ property
- Update XAttribute Value where XAttribute Name = X
- Join Query on Entity Classes in ASP.net
- How to get a subset of columns from a table without requiring a new type in Linq
- Entity Framework How can I filter my results by a property of a navigation property?
- How to call extension method "ElementAt"of List<T> with reflection?
- Should I stick to LINQ in this simple case?
- EF DateTime formatting
- Fast multiple string compare
- Parsing XML with pairs of elements using XDocument and LINQ
- Logic behind updating object List using linq
- C# linq query with where subquery for each property
- Write a LINQ query for 2 tables
- How to extract data from website using AngleSharp & LINQ?
- Append OR subquery in Linq
- Trying to get distinct values using LINQ with database field as parameter