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 Lo开发者_开发知识库adOperation, 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
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;
精彩评论