Skip to main content
se añadieron 238 caracteres en el cuerpo
Origen Enlace
public IQueryable<T> GetAll(params Expression<Func<T, bool>>[]? filters) => QueryCore(filters);

private IQueryable<T> QueryCore(params Expression<Func<T, bool>>[]? filters)
        {
            try
            {
                Func<IQueryable<T>, Expression<Func<T, bool>>, IQueryable<T>>? func = ((current, expression) => current.Where(expression));
                DbSet<T> source = _dbContext.Set<T>();


                IQueryable<T> queryable = source.OfType<T>();

                
                if (!CollectionUtils.IsNullOrEmpty(filters))
                {
                    queryable = filters!.Aggregate(queryable, func);
                }
                return queryable;
            }
            catch (Exception dbEx)
            {
                throw dbEx;  
            }
        }

esto me sirvio funciona muy bien, para usarlo seria algo asi :

var xd = 15;
var lol = "string";
var filters=new Expression<Func<Artist,bool>>[]
        {
            f => f.Id == xd,
            f => f.Name == lol
        };
public IQueryable<T> GetAll(params Expression<Func<T, bool>>[]? filters) => QueryCore(filters);

private IQueryable<T> QueryCore(params Expression<Func<T, bool>>[]? filters)
        {
            try
            {
                Func<IQueryable<T>, Expression<Func<T, bool>>, IQueryable<T>>? func = ((current, expression) => current.Where(expression));
                DbSet<T> source = _dbContext.Set<T>();


                IQueryable<T> queryable = source.OfType<T>();

                
                if (!CollectionUtils.IsNullOrEmpty(filters))
                {
                    queryable = filters!.Aggregate(queryable, func);
                }
                return queryable;
            }
            catch (Exception dbEx)
            {
                throw dbEx;  
            }
        }
public IQueryable<T> GetAll(params Expression<Func<T, bool>>[]? filters) => QueryCore(filters);

private IQueryable<T> QueryCore(params Expression<Func<T, bool>>[]? filters)
        {
            try
            {
                Func<IQueryable<T>, Expression<Func<T, bool>>, IQueryable<T>>? func = ((current, expression) => current.Where(expression));
                DbSet<T> source = _dbContext.Set<T>();


                IQueryable<T> queryable = source.OfType<T>();

                
                if (!CollectionUtils.IsNullOrEmpty(filters))
                {
                    queryable = filters!.Aggregate(queryable, func);
                }
                return queryable;
            }
            catch (Exception dbEx)
            {
                throw dbEx;  
            }
        }

esto me sirvio funciona muy bien, para usarlo seria algo asi :

var xd = 15;
var lol = "string";
var filters=new Expression<Func<Artist,bool>>[]
        {
            f => f.Id == xd,
            f => f.Name == lol
        };
Origen Enlace

public IQueryable<T> GetAll(params Expression<Func<T, bool>>[]? filters) => QueryCore(filters);

private IQueryable<T> QueryCore(params Expression<Func<T, bool>>[]? filters)
        {
            try
            {
                Func<IQueryable<T>, Expression<Func<T, bool>>, IQueryable<T>>? func = ((current, expression) => current.Where(expression));
                DbSet<T> source = _dbContext.Set<T>();


                IQueryable<T> queryable = source.OfType<T>();

                
                if (!CollectionUtils.IsNullOrEmpty(filters))
                {
                    queryable = filters!.Aggregate(queryable, func);
                }
                return queryable;
            }
            catch (Exception dbEx)
            {
                throw dbEx;  
            }
        }