I am deep in the weeds here and pretty well confused. This answer helped a ton: https://stackoverflow.com/a/8315901/6368685
However, the line:
var equal = Expression.Equal(prop, soap);
I need it to be .Contains('Soap')
. Which has not been straightforward.
public void GetValReflection(string columnName, string columnValSearch)
{
IQueryable<Data.Classes.Models.Database.table1> dbQuery = (from o in _db.table1 select o);
PropertyInfo columnNameRef = typeof(Data.Classes.Models.Database.table1).GetProperty(columnName);
dbQuery = dbQuery.Where(u => ((string)columnNameRef.GetValue(u)).Contains(columnValSearch));
}
I am given the name of the database column in string format that is the same as the variable name within the Database context model (columnName
). I am also given what value needs to be contained within the row of that column to return said row (columnValSearch
).
I know I can't use reflection right in a .Where()
clause, but I learned that you can build one from the link above. I am just having trouble with how to build one with .Contains()
. This was another answer I found, but having trouble fitting it to my case.
https://stackoverflow.com/a/59676525/6368685