Hi,
I want to use a generic repository to standardise some of my data access. What I want is to be able to have a function defined in the interface representing the basic fields of my entity, so that I can use it to filter the results. This should be compilable into Linq-To-Sql.
e.g.
interface IEntity {
Expression<func<bool>> FilterQuery(string filter)
}
partial class AnEntity : IEntity
{
public string AName {get; set;}
Expression<func<bool>> FilterQuery(string filter)
{
return AName.Contains(filter);
}
}
class List<T> : where T : class, IEntity
{
private IQueryable<T> items;
public IQueryable<T> show(string filter)
{
items = items.Where(AN => AN.FilterQuery(filter));
return items;
}
}
However, I typically get errors like:
Cannot convert lambda expression to delegate type '
System.Func<T,int,bool>
' because some of the return types in the block are not implicitly convertible to the delegate return type
What is the best way of achieving my goal, of having something generic defined on an entity which can be using in a linq to sql where clause?