Was ist der beste Weg, eine dynamische WHERE-Klausel zu einer LINQ-Anweisung zusammenzustellen?Dynamische WHERE-Klausel in LINQ
Ich habe mehrere Dutzend Kontrollkästchen in einem Formular und sie am Übergang zurück: Wörterbuch < String, List <String> > (Dictionary < Feldname, List <Werte> >) auf meine LINQ-Abfrage.
public IOrderedQueryable<ProductDetail> GetProductList(string productGroupName, string productTypeName, Dictionary<string,List<string>> filterDictionary)
{
var q = from c in db.ProductDetail
where c.ProductGroupName == productGroupName && c.ProductTypeName == productTypeName
// insert dynamic filter here
orderby c.ProductTypeName
select c;
return q;
}
Es gibt eine portierte Version auf Github (https://github.com/kahanu/System.Linq.Dynamic), zu der ich beitragen und helfen zu verwalten. –