I'm trying to do the following generic method to search entities in a database:
// 'atributo' is the name of the attribute to search against
public List<TEntity> buscar<TEntity>(string valor, string atributo) where TEntity : class
{
var matches = from m in db.Set<TEntity>()
where m.GetType().GetProperty(atributo).GetValue(m, null).ToString().Contains(valor)
select m;
return matches.ToList();
}
Of course I'm getting the exception:
LINQ to Entities does not recognize the method 'System.String ToString()' method
And I know that GetType(), GetProperty() and GetValue() are invalid LINQ methods too.
I can't figure out how to use the invalid methods before the query.
Any ideas?
TIA