开发者

RIA Services get list of entities

I am working on a Silverlight application using RIA services with Entities Framework.

Forgive me, i'm fairly new with Ria services, but how do i go about getting a list of objects from the db without doing a load operation?

Example: I have an Employees table, in this table there's a IsSupervisor flag. I want to show a list of employees in a grid with a combobox cell bound to a list of supervisors (employees where isSupervisor = true).

The problem i have is that when the list of supervisors come back, the employee list 开发者_如何转开发only displays supervisors.

I hope this makes sense....


It's hard to really say without seeing your code, as RIA Services is pretty darn flexible.

It sounds like you are binding a DataGrid to your DomainContext's Employee EntitySet, and then making two calls to the server, one to get all employees, then one to get supervisors. If this is the case then yes your second call can wipe out the first one (depends on how you have LoadBehavior set).

But if you are querying the db to get all employees, then you already have the supervisors on the client side. Just create a separate collection that only contains the supervisors, and bind the ComboBox to this. Something like:

private void OnEmployeesLoaded(LoadOperation<Employee> loadOp) {
    if(!loadOp.HasError) {
        Employees = new List<Employee>(loadOp.Entities);
        Supervisors = new List<Employee>(loadOp.Entities.Where(e => e.IsSupervisor));
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜