End Result
I need to be able to search any database table for all rows that contain the given search string somewhere in any of the columns.
Current Implementation
I'm using anonymous types to handle the case when an anonymous select
lambda statement is used. Currently, using reflection, I can loop through the PropertyInfo[]
of the given anonymous type, get the values one by one and compare them to my search string.
var type = ob.GetType();
foreach (PropertyInfo prop in type.GetProperties())
{
var val = prop.GetValue(ob, null);
if (val.ToString().Contains(search)) return true;
}
The Problem
This implementation works great for anonymous lists. However, when using IQueryables
that map to SQL via EntityFramework, it doesn't because lambda expressions cannot build SQL queries that use c# in the query. The only path I've been able to find so far is creating a complex Expression tree to mimic the foreach
loop required to loop through and test all of the PropertyInfo
items associated with the anonymous object.
Is there a another way to do this or am I going to have to dig through some Expression tree articles?