Hello all
I am using asp.net 4.5 with code first using the repository pattern in c#.
base class :
public interface IAuditableEntity
{
...
string DeletedBy { get; set; }
DateTime? DeletedDate { get; set; }
bool IsDeleted { get; set; }
}
public abstract class AuditableEntity: IAuditableEntity
{
...
public string DeletedBy { get; set; }
public DateTime? DeletedDate { get; set; }
public bool IsDeleted { get;set; }
}
class:
public class Group : AuditableEntity
{
public int Id {get;set;}
public string Code { get; set; }
public string Name { get; set; }
public GroupType Type { get; set; }
public string Description { get; set; }
public int? ParentId { get; set; }
}
Repository Base :
public class RepositoryBase<T> : IRepository<T> where T : class
{
protected DbContext _entities;
protected DbSet<T> dbSet;
#endregion
public RepositoryBase(DbContext context)
{
_entities = context;
dbSet = context.Set<T>();
}
...
public virtual IQueryable<T> GetAll()
{
try
{
return dbSet;
}
catch (Exception ex)
{
throw ex;
}
}
public virtual IQueryable<T> GetMany(Expression<Func<T, bool>> where)
{
return dbSet.Where(where);
}
...
}
My Question:
i want to add expression in `GetAll` and `GetMany` function if Repositorybase T use `IAuditableEntry`
What I have tried:
public virtual IQueryable<T> GetAll()
{
try
{
return dbSet.Where(x=> x is IAuditableEntity && !((IAuditableEntity)x).IsDeleted);
}
catch (Exception ex)
{
throw ex;
}
}
When i used this
return dbSet.Where(x=> x is IAuditableEntity && !((IAuditableEntity)x).IsDeleted);
it show error like :
The 'TypeIs' expression with an input of type
'Group' and a check of type
'Base.IAuditableEntity' is not supported. Only entity
types and complex types are supported in LINQ to Entities queries.