RIA服务:包括选择(很多)不工作 [英] RIA Services : Include with Select(Many) not Working
问题描述
我有两个实体类型:文件
(有一个客户
)和客户
(具有收藏文件
)
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.
查询看起来是这样的:
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....
我已经尝试了一切,我可以想到的,包括包含(Documents.Customer)的
,包含(客户)
等。
I have tried everything I can think of including Include("Documents.Customer")
,Include("Customer")
,etc.
我绝对有 IncludeAttribute
中的元数据集。
I definitely have the IncludeAttribute
set in the metadata.
的思考?这甚至可能?
谢谢!
推荐答案
而不是使用投影和的SelectMany
,我用写LINQ查询联接:
Instead of using projection and SelectMany
, I wrote a LINQ query using a join:
var v = from cust in (from c in this.ObjectContext.Customers
where (c.CustomerName.Contains(filterText) || c.CustomerNumber.Contains(filterText)) select c)
join doc in this.ObjectContext.Documents on cust.CustomerNumber equals doc.CustomerNumber
where doc.Date >= startDate && doc.Date <= endDate
select doc;
return ((ObjectQuery<Document>)v).Include("Customer").AsQueryable<Document>();
这解决了这个问题!
这篇关于RIA服务:包括选择(很多)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!