c# - Dynamic linq query with join -
here try of dynamic linq query join. try list of unique categories, brands , other criteria present in last reading in database. passed query (brand, category etc.) defined @ runtime.
i read best way of doing func's, predicates etc., think beyond capacity @ stage. i'm trying easier way query string, got working simpler case, i'm doing wrong here join. if plain select product.category intellisense of course works, not in string in select clause.
public ienumerable<string> getfilteritems(string dbcolumn) { var filteritems = new list<string>(); return (from reading in helper.latestreadings reading.distributor != helper.client join product in helper.context.products on reading.productid equals product.skucode select ("product." + dbcolumn)).distinct(); }
you can use reflection achieve this
public ienumerable<string> getfilteritems(string dbcolumn) { var filteritems = new list<string>(); var productlist = reading in helper.latestreadings reading.distributor != helper.client join product in helper.context.products on reading.productid equals product.skucode select product; return productlist.select(x=>x.gettype().getproperty(dbcolumn).getvalue(x)).cast<string>().distinct(); }
Comments
Post a Comment