Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Problem in Silverlight project in ASP.NET
Hi,
I want to make a simple Silverlight application in ASP.NET and LINQ. I have two talbe
Student :[student_id,student_name,address, phone,country_id]
Country :[country_id,country_name]

Thiw tow table is join by country_id.
I have inluced a LINQ Data Class in my project.
I have included a Silverlight-Enabled-WCF-Serfice. In this service I have made tow method and there code is like
        [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();
        }
 
Then I add a service reference of that WCF service. Then I include a DataGrid in my silverlight .xml file.
Now I want to show all the students in that DataGrid. For this I have written the following code
 
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;
        }
 
Then I build the whole project and found no error. If I run the project then I found an error and it is--

An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at Silverlight.WCFServiceReference.LoadStudentCompletedEventArgs.get_Result()
at Silverlight.Home.oWCFServiceClient_LoadStudentCompleted(Object sender, LoadStudentCompletedEventArgse)
at Silverlight.WCFServiceReference.WCFServiceClient.OnLoadStudentCompleted(Object state)

 
If I remove county table form the LINQ class and remove LoadCountry() method form the service and call LoadStudent() method form silverlight form then it runs accurately and all the data is displayed in my DataGrid.
If I remove student table form the LINQ class and remove LoadStudent() method form the service then LoadCountry() method runs accurately. Both methods are not work if the present same time in LINQ WCF Service .
 
NB: Both tables has data. If I run a SQL join query then it returns data
 

I can’t understand what the problem is.
 
Is there anyone to help me regarding this problem?
 
Thanks in advance.
Rashed
Posted 9-Oct-12 22:11pm
Edited 9-Oct-12 23:29pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

plz check Collection Countries is not null
 
[OperationContract]
     public List<Country> LoadCountry()
      {
       if(oLINQDataClassesDataContext.Countries!=null &&             oLINQDataClassesDataContext.Countries.Rows.Count >0)
           {
            var result = from coun in oLINQDataClassesDataContext.Countries
                         select coun;
            return result.ToList();
            }
        }
  Permalink  
Comments
vasim sajad at 10-Oct-12 3:59am
   
check whether it contains row
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

go to properties of dbml file and change the Serialization mode to unidirectional
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100