Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SL:为什么我的DomainService将我的结果查询返回为null?_C#_Silverlight_Wcf Ria Services_Domainservices - Fatal编程技术网

C# SL:为什么我的DomainService将我的结果查询返回为null?

C# SL:为什么我的DomainService将我的结果查询返回为null?,c#,silverlight,wcf-ria-services,domainservices,C#,Silverlight,Wcf Ria Services,Domainservices,我现在在Silverlight和RIA服务公司工作 在我的项目中,我有一个DomainService和一个AuthenticationService 当我进行身份验证时,我意识到如果我调试ObjectContext,我可以看到数据库中的所有记录 但是当我使用DomainService时,我试图从默认查询中获取对象,例如GetStudents,但查询总是返回0个元素 但是从它开始,我想做一个插入,它可以工作 // Has finished var j

我现在在Silverlight和RIA服务公司工作

在我的项目中,我有一个DomainService和一个AuthenticationService

当我进行身份验证时,我意识到如果我调试
ObjectContext
,我可以看到数据库中的所有记录

但是当我使用DomainService时,我试图从默认查询中获取对象,例如
GetStudents
,但查询总是返回0个元素

但是从它开始,我想做一个
插入
,它可以工作

            // Has finished
            var jsonObjects = JsonConvert.SerializeObject(Test, Formatting.Indented);

            var context = new DatabaseDomainContext();
            // it works!! add the object
            //Student newStudent = new Student();
            //newStudent.Id = "OPA-3DKCL2";
            //newStudent.FirstName = "Oscar";
            //newStudent.LastName = "Fimbres";

            //context.Students.Add(newStudent);
            //context.SubmitChanges();

            // all the time returns 0 elements
            var students2 = context.Load(context.GetStudentsQuery()).Entities;

            // the same
            var students = context.GetStudentsQuery();
            AnsweredTest answerTest = new AnsweredTest();
            answerTest.JsonTest = jsonObjects;
            answerTest.Date = DateTime.Now;
            //answerTest.Student = context.Students.SingleOrDefault(x => x.Id == "OPA-3DKCLS");


如果我缺少一个重要数据,请告诉我。

加载操作是异步的,您需要订阅
已完成的
事件并在那里获得结果:

var loadOperation = context.Load(context.GetStudentsQuery());
operation.Completed += OnStudentsLoaded;

private void OnStudentsLoaded(object sender, EventArgs e)
{
    var operation = sender as LoadOperation<Student>;
    if (operation == null)
    {
        throw new ArgumentException("sender is not LoadOpearation<Student>");
    }
    IEnumerable<Student> students = operation.Entities;

    //.....
}
var loadOperation=context.Load(context.GetStudentsQuery());
操作。已完成+=学生已加载;
StudentsLoaded上的私有无效(对象发送方、事件参数e)
{
var操作=发送方作为LoadOperation;
if(操作==null)
{
抛出新ArgumentException(“发送方不是LoadOperation”);
}
IEnumerable students=operation.enties;
//.....
}

谢谢dvvrd!它起作用了!但我不明白为什么互联网上的很多例子都不能说明这一点:哦,是的,这是个问题。我以前读过这个演练,遇到了和你一样的问题。我想一定有人建议他们重新措辞