In EFCore 1.1 there is .Include
var q = (from o in context.Company
where o.Id == CompanyId && !o.IsDelete
select o)
.Include(x => x.Personnel)
.ThenInclude(x => x.HomeAddress)
.First();
But they .Includealso .ThenIncludeallow properties. I want to create an extension method that modifies the original behavior to exclude IsDelete (the database is a soft delete)
public static IIncludableQueryable<TEntity, TProperty> AlongWith<TEntity, TProperty>(this IQueryable<TEntity> source, Expression<Func<TEntity, TProperty>> navigationPropertyPath) where TEntity : Domain.EntityBase
{
var result = source.Include(navigationPropertyPath);
return result;
}
My goal is to create an expression similar navigationPropertyPath, but enable validation for IsDelete
var type = typeof(Domain.EntityBase);
ParameterExpression pe = Expression.Parameter(type, "personnel");
var left = Expression.Property(pe, type.GetProperty("IsDelete"));
var right = Expression.Constant(false);
var predicateBody = Expression.Equal(left, right);
var lambda = Expression.Lambda(navigationPropertyPath.Body, pe);
var navigationPropertyPathWithDeleteFalse = Expression.And(lambda, predicateBody);
Can I add && !IsDeletewhen for navigationPropertyPath?
source
share