I'm trying to prefilter the queries if the Entity implement a specific interface.
for that I'm using a filter expression that is doing a cast.
I first check if the Entity implement the function. If so I filter on a property of the interface.
Here is my function:
private static DataSource2<TEntity> GetDataSource<TEntity>(ILinqMetaData metadata) where TEntity : class,IEntity2
{
if (typeof(IDeactivableEntity).IsAssignableFrom(typeof(TEntity)))
{
//We entity is deactivable entity, we should only returned the entities which are not deleted.
var datasource = metadata.GetQueryableForEntity((int)Enum.Parse(typeof(EntityType), typeof(TEntity).Name)) as DataSource2<TEntity>;
return datasource.ToList().Where(x => !(x as IDeactivableEntity).IsDeleted) as DataSource2<TEntity>;
}
return metadata.GetQueryableForEntity((int)Enum.Parse(typeof(EntityType), typeof(TEntity).Name)) as DataSource2<TEntity>;
}
Unfortunately everytime I do a call like:
GetDataSource<CountryEntity>().ToList();
Where CountryEntity implement the interface IDeactivableEntity...
I get an error.
The error I get is:
Value cannot be null. Parameter name: source
Any idea.