I am following up on this answer this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.
public IQueryable<TEntity> EmptyEnumerable()
{
return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
var enumerable = this.EmptyEnumerable();
var param = Expression.Parameter(typeof(TEntity));
if(filter != null)
{
enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
var mce = enumerable.Expression as MethodCallExpression;
if(mce != null)
{
var quote = mce.Arguments[1] as UnaryExpression;
if(quote != null)
{
return quote.Operand as Expression<Func<TEntity, bool>>;
}
}
}
return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}
My questions are:
- Is there anything that I should be checking, which I am not already checking?
- Is returning a truth expression a sensible default?
Any refactorings/improvements are welcome.
I am following up on this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.
public IQueryable<TEntity> EmptyEnumerable()
{
return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
var enumerable = this.EmptyEnumerable();
var param = Expression.Parameter(typeof(TEntity));
if(filter != null)
{
enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
var mce = enumerable.Expression as MethodCallExpression;
if(mce != null)
{
var quote = mce.Arguments[1] as UnaryExpression;
if(quote != null)
{
return quote.Operand as Expression<Func<TEntity, bool>>;
}
}
}
return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}
My questions are:
- Is there anything that I should be checking, which I am not already checking?
- Is returning a truth expression a sensible default?
Any refactorings/improvements are welcome.
I am following up on this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.
public IQueryable<TEntity> EmptyEnumerable()
{
return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
var enumerable = this.EmptyEnumerable();
var param = Expression.Parameter(typeof(TEntity));
if(filter != null)
{
enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
var mce = enumerable.Expression as MethodCallExpression;
if(mce != null)
{
var quote = mce.Arguments[1] as UnaryExpression;
if(quote != null)
{
return quote.Operand as Expression<Func<TEntity, bool>>;
}
}
}
return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}
My questions are:
- Is there anything that I should be checking, which I am not already checking?
- Is returning a truth expression a sensible default?
Any refactorings/improvements are welcome.
Parsing ODataQueryOptions<T> to Expression<Func<T, bool>>
I am following up on this answer for a scenario that I am currently working on. Like the OP, I am too concerned about the longevity of the code.
public IQueryable<TEntity> EmptyEnumerable()
{
return Enumerable.Empty<TEntity>().AsQueryable();
}
private Expression<Func<TEntity, bool>> GetFilterExpression(FilterQueryOption filter)
{
var enumerable = this.EmptyEnumerable();
var param = Expression.Parameter(typeof(TEntity));
if(filter != null)
{
enumerable = (IQueryable<TEntity>)filter.ApplyTo(enumerable, new ODataQuerySettings());
var mce = enumerable.Expression as MethodCallExpression;
if(mce != null)
{
var quote = mce.Arguments[1] as UnaryExpression;
if(quote != null)
{
return quote.Operand as Expression<Func<TEntity, bool>>;
}
}
}
return Expression.Lambda<Func<TEntity, bool>>(Expression.Constant(true), param);
}
My questions are:
- Is there anything that I should be checking, which I am not already checking?
- Is returning a truth expression a sensible default?
Any refactorings/improvements are welcome.