1

Possible Duplicate:
Alternative to nested type of type Expression<Func<T>>

Playing with a method in a Facade / Repository, gleaned from a MSDN article, I produced:

public virtual IEnumerable<TEntity> Fetch(
    Expression<Func<TEntity, bool>> filter,
    Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy,
    string includeProperties)
{
    IQueryable<TEntity> query = this.DbContext.Set<TEntity>();

    if (filter != null)
    {
        query = query.Where(filter);
    }

    if (!string.IsNullOrEmpty(includeProperties))
    {
        foreach (var includeProperty in includeProperties
            .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
        {
            query = query.Include(includeProperty);
        }
    }

    return orderBy == null 
        ? query 
        : orderBy(query);
}

Code Analysis generates 2 warnings, as follows:

CA1006 : Microsoft.Design : Consider a design where 'MyType<TDbContext, TEntity>.Fetch(Expression<Func<TEntity, bool>>, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>, string)' doesn't nest generic type 'Expression<Func<TEntity, bool>>'.

CA1006 : Microsoft.Design : Consider a design where 'MyType<TDbContext, TEntity>.Fetch(Expression<Func<TEntity, bool>>, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>, string)' doesn't nest generic type 'Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>'.

Now, I know they are only warnings and I am free to suppress them (and probably will as they appear overly pedantic under this scenario). However, out of interest, is there a possible design that accomplishes the same as this method without incurring the Code Analysis warnings?

Richard

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
Richard
  • 5,810
  • 6
  • 29
  • 36

0 Answers0