You can use reflection for this, but you're facing some rather ugly code. However, if you're willing to change your models a little bit, you can do that in a relatively straightforward way.
Create an interface that has one property - valid, like so:
interface IValid
{
bool valid { get; set; }
}
Make sure all your models that have this valid field implement the interface. Then you can do something like this:
List<T> GetValid<T>(DbContext context) where T: IValid
{
return context.Set<T>().Where(x=>x.valid).ToList()
}
By having your models implement the interface, you can use an ordinary LINQ expression and have the compiler sort everything out
.