0

我现在正在使用 Silverlight 和 RIA 服务。

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

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

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

但是从中,我想做一个Insert,它有效

            // 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");

在此处输入图像描述

如果我遗漏了重要数据,请告诉我。

4

1 回答 1

2

Load operation is asyncronious, you need to subscribe to Completed event and get result there:

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;

    //.....
}
于 2012-08-19T20:20:19.957 回答