Trying to Select an object with a child collection using conditional "Include" on collection

Dec 11, 2014 at 5:54 PM
I am trying to extract an object with a collection of a child objects with a conditional Include (to only "include" certain child objects) but I get the error below. I am able to replicate error with Northwind database. Please see my Northwind query that causes error with Northwind (I added a "Where" on "Include" of "Orders". Any help would be appreciated.

Thanks.

ERROR
Additional information: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
ERROR

CODE
var query = unitOfWork.RepositoryAsync<Customer>()
.Query(c => c.CustomerID == "BOLID")
.Include(o => o.Orders.Where(o2 => o2.EmployeeID == 4))
.SelectAsync();

Customer customer = query.Result.FirstOrDefault<Customer>();
CODE
Coordinator
Dec 18, 2014 at 10:28 PM
Marked as answer by lelong37 on 12/18/2014 at 3:28 PM
Feb 12, 2015 at 8:52 PM
The second link provided has code that cannot work :
var customers = _customerService
                    .Queryable()
                    .Include(t => t
                        .Orders
                        .Select(u => u.OrderDetails))
                    .Where(t => t.CustomerID == key)
                   .OrderBy(t => t.CompanyName)
                   .ThenBy(t => t.ContactName);
The "Include" cannot be called on "Queryable".
Mar 7, 2015 at 5:09 AM
Edited Mar 7, 2015 at 5:22 AM
maximejobin wrote:
The second link provided has code that cannot work :
var customers = _customerService
                    .Queryable()
                    .Include(t => t
                        .Orders
                        .Select(u => u.OrderDetails))
                    .Where(t => t.CustomerID == key)
                   .OrderBy(t => t.CompanyName)
                   .ThenBy(t => t.ContactName);
The "Include" cannot be called on "Queryable".
You need to include entity framework in your repository project and then:
using System.Data.Entity;

This should give you access to include.