I created a Generic Repository class like below :
public abstract class Repository<TEntity, TIdentifier> : IRepository<TEntity, TIdentifier> where TEntity : class
{
//TEntity is type of DBSet and TIdentifier is name of SQL Table's Id column
protected Repository(DbContext context)
{
Context = context;
DBSet = Context.Set<TEntity>();
}
}
in this Class we have a method named SelectAll as the following :
[DataObjectMethod(DataObjectMethodType.Select, true)]
public IEnumerable<TEntity> SelectAll(IEnumerable<TIdentifier> ids, List<string> includeNavigationProperties = null)
{
ParameterExpression parameter = Expression.Parameter(typeof(TEntity), "entity");
MemberExpression leftParam = Expression.MakeMemberAccess(parameter, typeof(TEntity).GetProperty(IdentifierColumn));
Expression body = parameter;
foreach (TIdentifier identifier in ids)
{
var rightParam = Expression.Constant(identifier);
body = Expression.Or(body, Expression.Equal(leftParam, rightParam));//Exception
}
return (IEnumerable<TEntity>) DBSet.Select(Expression.Lambda<Func<TEntity, bool>>(body, parameter));
}
As you can see I wanted to select all rows with Id column in IEnumerable<TIdentifier> ids. But the following exception has occurred:
The binary operator Or is not defined for the types ‘DAL.Tag’ and ‘System.Boolean’
If you execute your logic on paper you’ll get something like
probably not what you meant unless Entity happens to be a bool.