2012-10-10 19 views
0

我想在ASP.NET和LINQ中創建一個簡單的Silverlight應用程序。我有兩個talbe使用LINQ的ASP.NET中的Silverlight項目出錯

學生:[student_id數據,student_name,地址,電話,COUNTRY_ID]國家 :[COUNTRY_ID,COUNTRY_NAME]

Thiw拖表是COUNTRY_ID加入。 我在我的項目中嵌入了一個LINQ數據類。 我已經包含了Silverlight-Enabled-WCF-Serfice。在這項服務中,我做了兩種方法,代碼就像

[OperationContract] 
     public List<Country> LoadCountry() 
     { 
      var result = from coun in oLINQDataClassesDataContext.Countries 
         select coun; 
      return result.ToList(); 
     } 

     [OperationContract] 
     public IList<Student> LoadStudent() 
     { 

      var result = from std in oLINQDataClassesDataContext.Students 
         select std;   
      return result.ToList(); 
     } 

然後我添加該WCF服務的服務引用。然後我在我的Silverlight .xml文件中包含一個DataGrid。

現在我想顯示該DataGrid中的所有學生。爲此我寫了以下代碼

WCFServiceReference.WCFServiceClient oWCFServiceClient = new WCFServiceReference.WCFServiceClient();

public Home() 
    { 
     InitializeComponent(); 
     oWCFServiceClient.LoadStudentCompleted += new EventHandler<WCFServiceReference.LoadStudentCompletedEventArgs>(oWCFServiceClient_LoadStudentCompleted); 
     oWCFServiceClient.LoadStudentAsync(); 

    } 

    void oWCFServiceClient_LoadStudentCompleted(object sender, WCFServiceReference.LoadStudentCompletedEventArgs e) 
    { 
     dataGrid1.ItemsSource = e.Result; 
    } 

然後我建立了整個項目,發現沒有錯誤。如果我運行該項目,那麼我發現一個錯誤,它是 -

操作過程中發生異常,使結果無效。 檢查異常詳情的InnerException。在在 Silverlight.WCFServiceReference.WCFServiceClient.OnLoadStudentCompleted(對象 狀態 System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 在 Silverlight.WCFServiceReference.LoadStudentCompletedEventArgs.get_Result() 在Silverlight.Home.oWCFServiceClient_LoadStudentCompleted(對象 發件人,LoadStudentCompletedEventArgse) )

如果我刪除縣表格形式LINQ類和刪除LoadCountry()方法形成的服務和呼叫LoadStudent()方法形式的Silverlight形式,那麼它運行準確,所有的數據都顯示在我的DataGrid中。

如果我從LINQ類中刪除學生表,並從服務中刪除LoadStudent()方法,那麼LoadCountry()方法會正確運行。如果目前同時在LINQ & WCF服務中,兩種方法都不起作用。

注:兩個表都有數據。如果我運行SQL連接查詢,然後它返回數據

我不明白是什麼問題。

有沒有人可以幫我解決這個問題?

在此先感謝。 拉希德

+0

什麼是內部異常? –

+0

但我沒有發現任何異常.. –

回答

0

去的dbml文件的屬性並更改序列化模式爲單向