C# Silverlight RIA Services - Context.Load() does not support loading of multiple queries?
-
13-09-2019 - |
Question
The Scenario
Currently I have a c# silverlight business application. The application is hosted in Asp.net using the ADO.Net entity framework and a domain service class to read/write to/from my sql server database.
The Setup
Client UI
In my silverlight client interface I have an autocomplete box which uses a query to get a list of items relating to the search. The query is in my domain service class and looks as follows:
public IQueryable<Status> GetStatus()
{
var q = (from job in Context.Job
select job.Status).Distinct()
.Select(deliveryState => new Status
{
DeliveryState = deliveryState,
Count = Context.Job.Count
(job => job.Status.Trim() == deliveryState.Trim())
});
q = q.Where(job => job.DeliveryState != null);
return q;
}
Code Behind
Then in my code behind for the silverlight client interface xaml page, I load the query in the contructor using the following code:
var context = dds.DomainContext as InmZenDomainContext;
statusFilterBox.ItemsSource = context.Status;
context.Load(context.GetStatusQuery(), (lo) =>
{
//just to show you how to load..
//new ErrorWindow("Loaded.." + lo.Entities.Count()).Show();
}, null);
The Issue
The issue I have is what happens now if I add another autocomplete box to my client interface, and another Get query to perform a different type of search:
public IQueryable<ShortCode> GetShortCode()
{
var q = (from job in Context.Job
select job.ShortCode).Distinct()
.Select(name => new ShortCode
{
Name = name,
Count = Context.Job.Count
(job => job.ShortCode.Trim() == name.Trim())
});
q = q.Where(job => job.Name != null);
return q;
}
The issue arises due to the fact that the "Context.Load()" function does not support loading multiple queries. Also If I try to declare to separate "Context.Load()" - Only one of them works........
How can I get around this!?!
Solution
This is kind of an indirect answer to you question so take it or leave it.
I have multiple AutoCompleteBoxes on one screen but I am not using a DDS. I gave up the DDS a long time ago when I kept running into problems. The main thing that I dont like about the dds is that so much of the logic is in the view.
What I do is bind my ACB directly to the entity and use a custom filter to do my complex searches. The list that it searches is an entity list that I populate using the get command
public EntityList<Person> Person
{
get { return _DomainContext.Persons; }
}
I could go into more detail but if you are lock into using the DDS then I will leave it at that.
OTHER TIPS
There is one entity type per load, but there shouldn't be any problem having multiple loads running at the same time. Do you have Fiddler installed to watch what is actually going across the wire?