Print Page | Close Window

Filtered Includes

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3379
Printed Date: 28-Mar-2024 at 5:36am


Topic: Filtered Includes
Posted By: paul
Subject: Filtered Includes
Date Posted: 05-Apr-2012 at 8:26pm
I know it isn't possible with EF right now but I was curious what other people have done. This is what my ideal code looks like but since EF doesn't support filtered includes it won't work.

IEntityQuery<Model.Employee> query = Manager
    .Employees
    .Where(e => e.EmployeeId == employeeId)
    .Include(e => e.Person)
    .Include(e => e.Person.Address)
    .Include(e => e.Person.Address.Region)
    .Include(e => e.Person.Address.Region.RegionLocalizeds.Where(rl => rl.LanguageTypeId == CurrentLanguageTypeId));





Replies:
Posted By: sbelini
Date Posted: 06-Apr-2012 at 8:25am
Hi Paul,
 
Unfortunatelly, you won't be able to filter entities retrieved via Include.
However, a workaroud would be using select:
 
var employees = Manager.Employees.Where(e => e.EmployeeId == employeeId)
                                      .Include(e => e.Person)
                                      .Include(e => e.Person.Address)
                                      .Include(e => e.Person.Address.Region)
                                      .Select(e => new { Employee = e,
                                                                    RegionLocalizeds = e.Person.Address.Region.RegionLocalizeds.Where(rl => rl.LanguageTypeId == CurrentLanguageTypeId))
                                      .ToList()
                                      .Select(emp => emp.Employee;
 
 
There is a forum post at  http://www.ideablade.com/forum/forum_posts.asp?TID=2097&PID=8208#8208 - http://www.ideablade.com/forum/forum_posts.asp?TID=2097&PID=8208#8208  that address the same issue.
 
Regards,
   Silvio.
 


Posted By: paul
Date Posted: 09-Apr-2012 at 6:23pm
Any input from anyone? Should I cross-post to the Cocktail forum. I didn't want it to get lost after the holiday weekend. Thanks...


Posted By: sbelini
Date Posted: 10-Apr-2012 at 10:49am
Hi Paul,
 
Sorry for the delay.
I moved your last question to the Cocktail forum.
 
Silvio.



Print Page | Close Window