Trying to do a reflection call to table and invoke the where method. Use in MVC (2),
Data in entity framework. Could hardcode for the currently two tables that im trying to get data out off.
Trouble at how to invoke the where method.
And simply surprised that I did not find answer to this already? So if already answered, and iv not searched the right thing, im sure you'll let me know.
have the following
string search_table
PropertyInfo prop = database.GetType().GetProperty(search_table);
object table = prop.GetValue(WRG,null);
var methods = table.GetType().GetMethods();
var where_method = table.GetType().GetMethod("Where");
var result_data = where_method.Invoke(table, new object[]{"table", "table.-FIELD-NAME.Contains(search_string)"});
If not using reflection, then I would call the where method with var result_data = database.-TABEL-.Where(t => t.-FIELD.Contains(search_string));
So have tried copping that info into the invoke, nothing.
where invoke asks for: (object obj, object[] parameters)
thank you anyone pointing me in the right direction.
Where
is an extension method , usually defined in the System.Linq.Queryable
or System.Linq.Enumerable
classes, depending on whether or not the object implements IQueryable
.
The Enumerable
version expects a Func<T, bool>
parameter. The Queryable
version expects an Expression<Func<T, bool>>
parameter. Neither version accepts a string representation of the parameter. If you need to pass the parameter as a string, you'll need to look at the LINQ Dynamic Query library .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.