I'm trying to use generics to search on some Entities using search parameters defined in a int/string Dictionary. I have a search info class like:
public class SearchInfo<TEntity, TComparer>{
public Func<TEntity, TComparer> Search { get; set; }
public Func<string, TComparer> ConvertValueToSearchType { get; set; }
}
Say i'm searching on a Int64 my Search Info will be set up like:
var searchInfo = new SearchInfo<Entity, Int64>();
searchInfo.Search = new Func<Entity, Int64>(i => i.Child.Id);
searchInfo.ConvertValueToSearchType = new Func<string, Int64>(s=>Int64.Parse(s));
I'd like to be able to do
items = items.Where(i=> searchInfo.Search(i) == searchInfo.ConvertValueToSearchType(dictionary.Value));
However I keep getting the exception
An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code
Additional information: The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.
Anyone know how I can accomplish this?