tags:

views:

625

answers:

1

I got a problem that is just killing me. One of my CSLA object (let's say Parent) has many children (let's call them Children - a list of Child). Parent is a Editable Root (BusinessBase) and Children is an Editable Child List (BusinessListBase) and Child is Editable Child.

What I am trying to do is to do this: Parent x = Parent.GetParent(id); IQueryable y = Parent.MyChildren.OrderBy("Age DESC");

In theory, y then should be filled with a collection of children sorted descendingly by their age (assuming "Age" is a property of Child object).

But, what I got is that y.Count() = 0. Although if I do a Parent.MyChildren.Count() there aren't 0. Is this a bug in Dynamic LINQ or CSLA? This (the error) does not happen in readonly list for me.

Help! Joe

+1  A: 

Joe,

Here's a clue that might help. Your comment about the difference between an editable list and a readonly list got me curious, so I dug a little deeper.

Based on what I could tell from digging into the CSLA 3.5 code, BusinessListBase implements IQueryable (actually it's "C" in the CSLA code, as in "Child"). The ReadOnlyListBase class does not.

This may affect which Dynamic LINQ OrderBy extension method is being called (there are two), and the one for IQueryable simply calls the version of OrderBy for the regular IQueryable.

On the other hand, if you follow the trail of IQueryable in BusinessListBase, the Provider property (of type IQueryProvider) delegates to the CslaQueryProvider.

public IQueryProvider Provider
{
  get {
    return new Linq.CslaQueryProvider<T, C>(this);
  }
}

All of that to say, with the limited time I had to spend, I think delving further (with a debugger, duh!) into the CSLA LINQ stuff is probably warranted. From other discussion and follow-up elsewhere, I saw you also pointed to a bug/issue recorded for CSLA. Here's the link:

CSLA Issue ID 326 - OrderBy should return a LinqBindingList that works with Bound Grids

My suspicion is that it has more to do with BusinessListBase's implementation of IQueryable than anything else. And again, it doesn't look like ReadOnlyListBase implement IQueryable, either directly or via inheritance (in my copy of CSLA 3.5).

Hope that helps.

Jeff Miller

xagronaut
Yes, it seems like that it is a bug with CSLA's implementation of IQueryable. I will track the issue and try to do a code compare with 3.6 version. I am also using a 3.5 version of CSLA.
Johannes Setiabudi