I want to pass in a method three parameters. The Classname (table), the field and the keyword.
Then I would like to take with Entity Framework with reflection the table and find the fields that have the keyword.
Something like
public List<object> FilterOptions(string keyword, string className, string field)
{
var objectSet = (System.Data.Objects.ObjectSet<dynamic>)DataContext.GetType().GetProperty(className).GetValue(DataContext, null);
var options = objectSet.Where(x => x.GetType().GetProperty(field).GetValue(x, null) == keyword).ToList();
...
}
However I get “An expression tree may not contain a dynamic operation”
When I change <dynamic> to <object> I get an error again.
I think this is where you want to end up. You are wanting field names for your entities?
there is a property on the ObjectContext class called MetadataWorkspace. You can drill down to an EntitySet which has a property call MetadataProperties. Something like this.
see this link.
Hope this helps.
P.S. I also would recommend accepting more of your answers. You only have a 33% accept rate. Which means your question will eventually just get passed by. Remember if you found the answer somewhere else you can answer your own question. :0)