I have a Silverlight app using mvvm with ria services. I have a textbox on the view that the user puts in a Job Number and clicks find. This find button is using the ICommand in xaml to go here..
public ICommand FindJob
{
get
{
return new DelegateCommand(BeginFindJob, (o) => true);
}
}
public void BeginFindJob(object o)
{
if (!IsDesignTime)
{
IsLoading = true;
string jobnum = o.ToString();
OnPropertyChanged("IsLoading");
LoadOperation<Job> loadOp = _context.Load<Job>(_context.GetJobsByJobNumQuery(jobnum));
loadOp.Completed += new EventHandler(loadOp_Completed);
}
}
It uses the GetJobsByJobNumQuery in my ria service like so..
public IQueryable<Job> GetJobsByJobNum(string JobNum)
{
var query = ((from j in this.ObjectContext.Jobs
where j.JobNumber == JobNum
select j) as ObjectQuery<Job>).Include("JobHeadings").Include("JobContracts").Include("JobTags").Include("JobMarket");
return query;
}
Im wanting it to return all the information about the job, so i wrote the query above to include all those relationships. Putting a breakpoint on the linq query and looking at the results, it has exactly what I wont. All the fields, JobHeadings and Contracts are working and bringing back all the bindings to that job. So now I bring that query back in my viewmodel and populate the fields, like so..
void loadOp_Completed(object sender, EventArgs e)
{
try
{
LoadOperation<Job> loadOp = sender as LoadOperation<Job>;
if (!loadOp.HasError)
{
_job = loadOp.Entities.FirstOrDefault<Job>();
base.IsLoading = false;
base.ProgressBarVisibility = Visibility.Collapsed;
base.OnPropertyChanged("IsLoading");
base.OnPropertyChanged("ProgressBarVisibility");
base.OnPropertyChanged("CurrentJob");
}
}
catch (Exception ex)
{
}
}
My problem is, that no relationship data is coming back. All the basic Job info is coming back from the Job table in my db, but none of the info from the related tables is coming back in my viewmodel. Putting a bp in and looking at _job, which should contain everything, all the relationship tables JobHeading/JobContract say ‘Enumeration yielded no results.’
So how is it not making its way back through to the viewmodel? What can i do to get the full query results put into the view/viewmodel so I can make changes?
This was a problem with the metadata service not picking up my latest table associations. After i went through that mess of regenerating the metadata, it was a simple matter of including and associating the correct keys. Thank you Quinton Bernhardt for your effort!