Reputation: 2381
I am new to WCF & RIA services and have what seems like a basic problem. I have multiple times in my silverlight 4 RC application dragged and dropped from my datasource window to my form and have returned information from the database. However I have a need to query the database for other information (Building a report) When I try to use the following code, I recieve no error, but I also do not get any information back from the service.
//Global
public UMSDomainContext _umsDomainContext = new UMSDomainContext();
//In the Initialization portion
_umsDomainContext.Load(_umsDomainContext.GetUMOptionsQuery());
//Queries
var name = from n in _umsDomainContext.UMOptions
select n.DistrictName;
var street1 = from c in _umsDomainContext.UMOptions
select c.Address1;
var street2 = from c in _umsDomainContext.UMOptions
select c.Address2;
var city = from c in _umsDomainContext.UMOptions
select c.City;
var zip = from c in _umsDomainContext.UMOptions
select c.Zip;
Im calling the current additional references.
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using System.ComponentModel.DataAnnotations;
using MTT.Web;
Upvotes: 1
Views: 3021
Reputation: 2381
The answer is very simple. The data when it was being loaded in was instantly being queried. While some applications will treat this procedurally, it seems Silverlight did not wait for the data to load before moving on. So I did the following:
public void LoadCustomerInformation()
{
//Load the Query
var loadOperation = _umsDomainContext.Load<UMOption>(_umsDomainContext.GetUMOptionsQuery());
//Create a event handler to run after the data is fully loaded.
loadOperation.Completed += new EventHandler(loadOperation_Completed);
}
void loadOperation_Completed(object sender, EventArgs e)
{
var name = (from n in _umsDomainContext.UMOptions
select n.DistrictName).First();
var street1 = from c in _umsDomainContext.UMOptions
select c.Address1;
var street2 = from c in _umsDomainContext.UMOptions
select c.Address2;
var city = from c in _umsDomainContext.UMOptions
select c.City;
var zip = from c in _umsDomainContext.UMOptions
select c.Zip;
//Other code to work with the data, etc...
}
Upvotes: 2