2013-12-23 33 views
0

我創建了一個Silverlight應用程序,在這裏我使用WCF RIA服務。 我的MainPage.xaml.cs無法從域服務獲取數據。在域名服務的方法是數據沒有從WCF RIA加載到SIlverlight MainPage.xaml.cs

public IQueryable<Measurement> GetMeasurements() 
{ 
    return this.ObjectContext.Measurements; 
} 

在MainPage.xaml.cs中的代碼如下

EntityQuery<Measurement> query = from p in service.GetMeasurementsQuery() select p; 

LoadOperation<Measurement> measurement = service.Load(query); 

請讓我知道了一些意見和建議。

+0

如果您描述了_expect_和_actually_正在發生什麼,您將得到更好的幫助。正如你所描述的,我沒有看到你的代碼有問題。 –

回答

1

RIA Services最常見的誤解是期待Web服務調用是同步的。實際上,Web服務調用是異步發生的。您不能期望Load()調用後立即加載結果。

// creates a query object. It is the equivalent of 
// "SELECT ... FROM ..." as a string. It doesn't actually 
// execute the query. 
EntityQuery<Measurement> query = 
    from p in service.GetMeasurementsQuery() select p; 

// sends the query to the server, but the server doesn't 
// return a result in the LoadOperation. The LoadOperation 
// will call you back when it is completed. 
LoadOperation<Measurement> measurement = service.Load(query); 

// when results are available, MeasurementLoaded is called 
measurement.Completed += MeasurementLoaded; 

// WARNING: do not have any code that expects results here. 
// var myMeasurements = service.Measurements; 


public void MeasurementLoaded(object sender, EventArgs eventArgs) 
{ 
    // you can use service.Measurements now. 
    var myMeasurements = service.Measurements; 
} 
相關問題