views:

98

answers:

1

For my repository using the entity framework i'm using the following method to return a IList.

 public virtual IList<TEntity> ToList(Func<TEntity, bool> expression)
 {   
    return  Context.CreateQuery<TEntity>("[" + EntitySetName + "]")
                                       .Where<TEntity>(expression).ToList();
 }

The expression parameter allows me to alter the result, but this is not to my expectations. Since createquery is first evaluated and afterwards my where is applied. I'm using this with tables with over 2 mil. records.

Does anybody have a solution how to keep the method generic, but with the abillity to control the outcome without loading all records first?

+1  A: 

You need to change the type of your argument to one which can be converted to SQL:

public virtual IList<TEntity> ToList(Expression<Func<TEntity, bool>> expression)

Note the Expression.

Craig Stuntz
Hi Craig, it works! thanks!
madC