ASP.NET中的Silverlight项目中的问题 [英] Problem in Silverlight project in ASP.NET

查看:43
本文介绍了ASP.NET中的Silverlight项目中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.NET中的Silverlight项目中的问题

我想在ASP.NET和LINQ中制作一个简单的Silverlight应用程序.我有两个桌布
学生:[学生ID,学生姓名,地址,电话,国家/地区ID]
国家:[country_id,country_name]

Thiw拖曳表由country_id加入.
我在项目中使用了LINQ数据类.
我包括了Silverlight-Enabled-WCF-Serfice.在此服务中,我使用了拖曳方法,并且代码类似于

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();
}



然后,我添加该WCF服务的服务引用.然后,在我的silverlight .xml文件中包含一个DataGrid.
现在,我想显示该DataGrid中的所有学生.为此,我编写了以下代码



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;
        }



然后,我构建了整个项目,没有发现错误.如果我运行该项目,那么我发现一个错误,那就是-

操作期间发生异常,使结果无效.检查InnerException以获取异常详细信息.
在System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
在Silverlight.WCFServiceReference.LoadStudentCompletedEventArgs.get_Result()
在Silverlight.Home.oWCFServiceClient_LoadStudentCompleted(Object sender,LoadStudentCompletedEventArgse)
在Silverlight.WCFServiceReference.WCFServiceClient.OnLoadStudentCompleted(对象状态)处


如果我从LINQ类中删除县表,而从服务中删除LoadCountry()方法,并从silverlight窗体中调用LoadStudent()方法,则它将准确地运行,并且所有数据都显示在我的DataGrid中.
如果我从LINQ类中删除学生表,并从服务中删除LoadStudent()方法,则LoadCountry()方法将准确运行.如果LINQ WCF Service中的当前时间相同,则这两种方法均无效.

注意:两个表都有数据.如果我运行SQL连接查询,那么它将返回数据


我不明白问题是什么.

关于这个问题,有没有人可以帮助我?

提前谢谢.
Rashed



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

推荐答案

plz检查收集国家/地区不为空

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();
            }
        }


转到dbml文件的属性,并将序列化模式更改为单向
go to properties of dbml file and change the Serialization mode to unidirectional


这篇关于ASP.NET中的Silverlight项目中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆