RIA Services - Silverlight 4.0 - Accessing Objects from Code

I have a strange situation. I have a simple project to test RIA functionality in Silverlight 4.0.

When I use a data source for a domain service, it works fine, but when I want to access the Context from the code and execute a simple query, I return 0 rows.

//test One with query provided to DataSource
var q = ctx.GetDoctorsWithPatientsAndHospitalQuery();
var result = ctx.Load(q);

//test Two using EntityQuery
EntityQuery<Doctor> query =
    from c in ctx.GetDoctorsWithPatientsAndHospitalQuery()
    select c;
LoadOperation<Doctor> loadOp = this.ctx.Load(query);
var result2 = loadOp.Entities;

//test Three using only entity and Linq
var result3 = ctx.Doctors.ToList();

It is also strange that when I want to add a new entity instance from the code, it works fine.

Doctor newDoctor = new Doctor()
{
    FirstName = firstNameTextBoxNew.Text,
    LastName = lastNameTextBoxNew.Text,
    Hospital_Id = tmp,
    Hospital = tmpH
};

ctx.Doctors.Add(newDoctor);
ctx.SubmitChanges();

Can someone tell me what I did wrong to make a selection from the code?

Regards, Daniel Skourowski

+3
source share
1 answer

"LoadOperation loadOp = this.ctx.Load(query);" , .

, Load(), .

async, .

"" , . . .

, .

, ( "result2 =" ). loadOp , :

LoadOperation<Doctor> loadOp = this.ctx.Load(query, loadOperation => 
    { 
        var result2 = loadOp.Entities;
    }, null);

** : , ... , . . loadOp loadOperation , result2 - . *

+3

Source: https://habr.com/ru/post/1761505/


All Articles