views:

28

answers:

1

Hello,

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

When I use data source for Domain Service it works great but when I want to access Context from code and execute simple query I returns 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();

Strange is also that when I want to add new entity instance from code it works great.

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

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

Can anyone could point me what I have done wrong to execute select from code?

Regards, Daniel Skowroński

+1  A: 

Calling "LoadOperation loadOp = this.ctx.Load(query);" from code is an async operation so you are basically checking the result before it completes.

If you want to see the results, you need to provide a callback, to the Load() method, that will execute after the data is loaded.

Data sources for domain services handle async updates, so keep propagating changes as and when load operations complete.

Your "save" works as it does not wait around for the result. You are manually checking the database afterwards. Not checking it in code.

Hope this helps.

As a quick check, try this (breakpoint on the "result2 =" line). Your loadOp is redundant in this example, but I did not want to change your code too much:

LoadOperation<Doctor> loadOp = this.ctx.Load(query, loadOperation => 
    { 
        var result2 = loadOp.Entities;
    });
Enough already
@HiTech MagicGreat,you have little mistake, "loadOp" inside should be "loadOperation" and instead "});" should be "}, null);"One last question would be:Can I create query on contex level or I must always return data via methods from domain services. I mean can I run async something like: var result3 = ctx.Doctors.ToList(); accessing directly entities.
Daniel
Sorry about the typos. I was doing it from memory and trying not to remove your existing code:) Re cxt.Doctors.ToList(), that would only work if Doctors was a query and not a collection (initially empty). Cheers.
Enough already