如何从多个LoadOperations中查询

本文关键字:LoadOperations 查询 | 更新日期: 2023-09-27 18:03:10

我试图通过WCF RIA服务使用LINQ合并两个查询。

每次我尝试查询LoadOperation创建的两个list,我从来没有得到任何结果。

下面是我的代码:
        LoadOperation<BTSLead_vw> lo = bictx.Load<BTSLead_vw>(bictx.GetBTSAttendedQuery().Take(2000));
        List<BTSLead_vw> btsattended = lo.Entities.ToList<BTSLead_vw>();
        LoadOperation<SyStudentApps> c2000lo = c2000ctx.Load<SyStudentApps>(c2000ctx.GetSyStudentAppsQuery().Take(2000));
        List<SyStudentApps> c2000apps = c2000lo.Entities.ToList<SyStudentApps>();
        var query = from bts in btsattended
                    join apps in c2000apps on bts.SystemLeadID equals apps.SyStudentID
                    select new BTSMasterQuery
                    {
                        SyStudentID = apps.SyStudentID,
                        EventDate = (DateTime)bts.EventDate,
                        StartTime = (DateTime)bts.StartTime,
                        SchoolStatus = apps.SchoolStatus,
                        LeadCat = apps.LeadCat,
                        StuNum = apps.StuNum,
                        AppRecDate = Convert.ToDateTime("11/01/2001")/*(from enroll in c2000ctx.GetAdEnrollsQuery()
                                      where enroll.SyStudentID == apps.SyStudentID
                                      select enroll.AppRecDate).First()*/,
                        TourAttended = (
                                      bts.InterestTitle == "Recording Arts Converted Group" ? "Recording Arts" :
                                      bts.InterestTitle == "Digital Arts Converted Group" ? "Digital Arts and Design" :
                                      bts.InterestTitle == "Unclear Converted Group" ? "Unknown" :
                                      bts.InterestTitle == "Film and Video Converted Group" ? "Film and Video" :
                                      bts.InterestTitle == "Show Production Converted Group" ? "Show Production" :
                                      bts.InterestTitle == "Gaming Converted Group" ? "Gaming" :
                                      bts.InterestTitle == "Entertainment Business Converted Group" ? "Entertainment Business" : bts.InterestTitle),
                        Gender = apps.Gender,
                        Ethnicity = apps.Ethnicity
                    };
        this.radGridView1.ItemsSource = query;

我已经做了几十次搜索,我明白它与列表绑定到GridView之前未加载的数据有关,但我不确定如何使用两个LoadOperations作为查询的一部分来解决这个问题。

谢谢,加勒特

如何从多个LoadOperations中查询

您正在设置异步加载,但不响应加载完成事件,也不使用加载操作对象(lo和c2000lo)的Entities成员。

您不能在数据来自服务器之前查询数据。在您的示例中,在加入lo的结果之前,您必须等待两个加载操作完成。实体和c2000 .实体。然而,这是一种不好的方法……

简化此操作的正常方法是在服务器上执行连接和提取,并为您想要的实际结果返回适当数据类型的IEnumerable。使用Silverlight,您总是希望将传输到客户端的数据量最小化。

你可以接受一个加载操作(比如你的lo),并在加载完成之前绑定到它的Entities成员,因为Entities只是一个容器,当数据加载完成时,它会通知绑定,如:

    LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
    CustomerGrid.ItemsSource = loadOp.Entities;