如何从多个LoadOperations中查询

发布于 2024-11-25 13:11:16 字数 2502 浏览 6 评论 0原文

我正在尝试通过 WCF RIA 服务使用 LINQ 将两个查询合并在一起。

每次我尝试查询从 LoadOperation 创建的两个列表时,我都不会得到任何结果。

这是我的代码:

        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 来解决这个问题查询的一部分。

谢谢,

加勒特

I am trying to merge two query together using LINQ via WCF RIA services.

Every time I try to query the two Lists that are created out of the LoadOperation, I never get any results.

Here is my code:

        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;

I have done dozens of searches, and I understand that it has to do with the data not being loaded before the List is bound to the GridView, but I'm not sure how to work around that with two LoadOperations as part of the query.

Thanks,

Garrett

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚笙 2024-12-02 13:11:16

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

在数据来自服务器之前,您无法查询数据。在您的示例中,您必须等待两个加载操作完成,然后才能加入 lo.Entities 和 c2000lo.Entities 的结果。然而,这是一个糟糕的方法......

简化这一点的正常方法是在服务器上进行联接和提取,并返回适当数据类型的 IEnumerable 以获得您想要的实际结果。使用 Silverlight,您总是希望最大限度地减少传输到客户端的数据量。

您可以在加载完成之前执行加载操作(如 lo)并绑定到其 Entities 成员,因为 Entities 只是一个容器,数据加载后通知绑定,如下所示:

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

You are setting up asynchronous loads, but not responding to the load completion events and not using the Entities members of your load operation objects (lo and c2000lo).

You cannot query the data before it comes from the server. In your example you would have to wait for two load operations to complete before joining the results of lo.Entities and c2000lo.Entities. That is however a bad way to do it...

The normal way to simplify this would be to do the join and extraction on the server and return an IEnumerable of an appropriate data type for just the actual results you want. With Silverlight you always want to minimise the amount of data transferred to the client.

You can take a load operation (like your lo) and bind to its Entities member before the load completes as Entities is just a container that will notify the binding when the data has loaded like:

    LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
    CustomerGrid.ItemsSource = loadOp.Entities;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文