I have two entity types: Document (has a Customer) and Customer (has a collection Documents)
My query is to get documents for a customer based on either the customer’s name or number.
The query looks like this:
public IQueryable<Document> GetCustomerDocuments(DateTime startDate, DateTime endDate, string filterText)
{
return this.ObjectContext.Customers
.Where(c => c.CustomerName.Contains(filterText) || c.CustomerNumber.Contains(filterText))
.SelectMany(c => c.Documents)
.Where(d => d.Date >= startDate && d.Date <= endDate);
}
When the query returns, I want it to include BOTH the Document and Customer entities….
I have tried everything I can think of including Include("Documents.Customer"),Include("Customer"),etc.
I definitely have the IncludeAttribute set in the metadata.
Thoughts? Is this even possible?
Thanks!
Instead of using projection and
SelectMany, I wrote a LINQ query using a join:This solves the problem!