Use Closure where when class is dynamic

2

I have a base class:

public class MinhaClasse<T> : Controller where T : class
{
    public List<T> BuscarVarios(string nome)
    {
        return db.Set<T>().Where(/*?????*/);
    }
}

How do I use cloister Where when my class is dynamic?

    
asked by anonymous 20.11.2015 / 16:30

1 answer

2

Although I can not see a reason to do so. The most I can think of right now to solve this problem is to ask for a Func<T, bool> instead of a string .

See in practice

public class MinhaClasse<T> : Controller where T : class
{
    public List<T> BuscarVarios(Func<T, bool> filtro)
    {
        return db.Set<T>().Where(filtro).ToList();
    }
}

At the time of using you would

minhaClassePersonalizada.BuscarVarios(x => x.Nome == "Joaquim");
    
20.11.2015 / 16:49