我有以下schema。
我想要做的是从StaffId的所选StaffAssignment中检索所有客户(和子属性)。
所以我写了以下查询:
from c in ObjectContext.Customers.Include("Assignments.Activities")
from a in c.Assignments
from sa in a.StaffAssignments
where sa.StaffId == staffId
select c
但是没有加载子属性(我在服务元数据文件中也添加了[Include])。
我做错了什么?
GTZ, 斯特凡。
答案 0 :(得分:0)
我遇到了同样的问题。
这是我的模型(取自NorthWind)
alt text http://i33.tinypic.com/5k0g3n.png
DomainService 如下所示:
[EnableClientAccess()]
public class DomainService1 : LinqToEntitiesDomainService<AdventureWorksLT2008Entities>
{
public IQueryable<Customer> GetCustomer()
{
return this.ObjectContext.Customer.Include("CustomerAddress").Include("CustomerAddress.Address");
}
}
我在所有导航属性中添加了[Include]属性:
public partial class Customer
{
internal sealed class CustomerMetadata
{
// Metadata classes are not meant to be instantiated.
private CustomerMetadata() { }
public string CompanyName { get; set; }
[Include]
public EntityCollection<CustomerAddress> CustomerAddress { get; set; }
在客户端代码中,我使用了这个:
var dc = new MyDomainContext();
var query = dc.GetCustomerQuery();
var op = dc.Load(query, loadOperation =>
{
var customer = loadOperation.Entities.FirstOrDefault();
var address = customer.CustomerAddress.FirstOrDefault().Address;
}, null);
请注意,这仅适用于:
另见this link。