if I’m passing in a string column name, how do I call a distinct list of items by property name?
private myEntities db = new myEntities();
...
//function passes in string
var vals = db.myEntityClass
.Select(v => v.????).Distinct() //I want this to be selected dynamically
If you are using .NET 4.0, here’s a post by David Fowler that makes use of the new dynamic type feature to create a DynamicQueryable and DynamicExpressionBuilder which allows you to reference entity properties dynamically.
Or.. if you rather get straight to it, he’s also created a library http://bitbucket.org/dfowler/dynamiclinq the encapsulates the functionality. It’s also on NuGet 🙂