public static IDomainIncludable <TEntity, TProperty> DomainInclude <TEntity, TProperty>( this IDomainIncludable <TEntity> source, Expression <Func <TEntity, TProperty> > navigationPropertyPath) { IRootDomainIncludable <TEntity> root = source.GetRoot(); return(new DomainIncludable <TEntity, TProperty>(root, DomainIncludeType.Include, navigationPropertyPath)); }
public static IDomainIncludable <TEntity, TProperty> DomainEnumerableThenInclude <TEntity, TPreviousProperty, TProperty>( this IDomainIncludable <TEntity, IEnumerable <TPreviousProperty> > source, Expression <Func <TPreviousProperty, TProperty> > navigationPropertyPath) where TEntity : class { IRootDomainIncludable <TEntity> root = source.GetRoot(); return(new EnumerableDomainIncludable <TEntity, TPreviousProperty, TProperty>(root, DomainIncludeType.ThenInclude, navigationPropertyPath)); }
private static IRootDomainIncludable <TEntity> GetRoot <TEntity>(this IDomainIncludable <TEntity> domainIncludable) { if (domainIncludable is IHasRootDomainInclude <TEntity> root) { return(root.GetRoot()); } else { throw new InvalidOperationException(); } }
public static IQueryable <TEntity> ApplyDomainIncludeForEF <TEntity>(this IQueryable <TEntity> query, IDomainIncludable <TEntity> include) { IQueryable <TEntity> resultQuery = query; if (include != null) { object result = query; foreach (Infos.DomainIncludeInfo item in include.IncludeInfos) { MethodInfo methodInfo = null; switch (item.IncludeType) { case Infos.DomainIncludeType.Include: { methodInfo = _efIncludeMethodInfo; break; } case Infos.DomainIncludeType.ThenInclude: { methodInfo = (item.IsEnumerable ? _efThenIncludeAfterEnumerableMethodInfo : _efThenIncludeAfterReferenceMethodInfo); break; } default: { break; } } result = methodInfo.MakeGenericMethod(item.GenericMethodArguments).Invoke(null, new object[] { result, item.Expression }); } resultQuery = result as IQueryable <TEntity>; } return(resultQuery); }