Linq and SortExpression

Posts   
 
    
csmac3144
User
Posts: 74
Joined: 12-Sep-2007
# Posted on: 07-Oct-2009 22:28:11   

We have a method that looks like this:

 public EntityCollection<RoleMatrixEntity> GetRoleMatricesCommon(IPredicateExpression bucket,
                                                                        RoleMatrixType type, SortExpression sorter,
                                                                        int? pageNumber, int? pageSize)

For several reasons we had to change the implementation from traditional LLBLgen code to Linq to LLBLgen. How can we use the SortExpression in a Linq query?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 08-Oct-2009 13:14:37   

That's a bit hard, as you then have to create an Expression tree as Linq works with extension method calls which accept property accesses on entities for example. So if you sort on RoleMatrix.Id in the sort expression, you have to call .OrderBy(rm=>rm.Id) on the RoleMatrix enumerable.

for the predicate expression you have the same problem. IMHO, if you have the method, use the method. Linq to LLBLGen Pro is build on top of our query api, it won't go away.

If you really must, you could look at the predicatebuilder class: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=14224 and use that approach to use OrderBy / ThenBy() calls instead of Where() calls.

Frans Bouma | Lead developer LLBLGen Pro