这个数据访问代码如何丢失数据?

时间:2009-11-03 05:03:31

标签: linq

我正在使用Wcf服务,在数据访问层中我使用此代码:

public BindingList getPeople(s)
{
    IQueryable<Personal> query;
    EntidadesDataContext dc = GetDC();
    DataLoadOptions loadOptions = new DataLoadOptions();
    loadOptions.LoadWith<People>(pp=> pp.PeopleDepartment);
    loadOptions.LoadWith<PeopleDepartment>(pd=> pd.Department); // is what I lose in the UI
    dc.LoadOptions = loadOptions;
    query = from people in dc.People select people;

    return QueryToBindingList(query);
}

此代码返回完整且完全符合我想要的数据,然后我从服务中调用它并将其添加到BindingList

peopleBindingList = currentConnection.ServiceClient.People_GetPeople();

at peopleBindingList我丢失了部门值....例如......

peopleBindingList.Select(pp=>pp.PeopleDepartament.First().Departament) ... returns Null

我首先检查它的数据是否会返回......

1 个答案:

答案 0 :(得分:0)

  

然后我从服务中调用它

我打赌你有一个不跨越服务范围的财产!检查所涉及类型的序列化。如果您正在使用DataContract序列化程序,请确保所需的所有属性都使用DataMember属性进行修饰。