protected override void IncludeNavigations(
            IQuerySource querySource,
            Type resultType,
            LambdaExpression accessorLambda,
            IReadOnlyList <INavigation> navigationPath,
            bool querySourceRequiresTracking)
        {
            Check.NotNull(querySource, nameof(querySource));
            Check.NotNull(resultType, nameof(resultType));
            Check.NotNull(accessorLambda, nameof(accessorLambda));
            Check.NotNull(navigationPath, nameof(navigationPath));

            var primaryKeyParameter        = Expression.Parameter(typeof(EntityKey));
            var relatedKeyFactoryParameter = Expression.Parameter(typeof(Func <IValueReader, EntityKey>));

            Expression
                = Expression.Call(
                      _includeMethodInfo.MakeGenericMethod(resultType),
                      QueryContextParameter,
                      Expression,
                      Expression.Constant(navigationPath),
                      accessorLambda,
                      Expression.NewArrayInit(
                          typeof(RelatedEntitiesLoader),
                          navigationPath.Select(
                              n =>
            {
                var targetType = n.GetTargetType();

                var materializer
                    = new MaterializerFactory(
                          QueryCompilationContext
                          .EntityMaterializerSource)
                      .CreateMaterializer(targetType);

                return(Expression.Lambda <RelatedEntitiesLoader>(
                           Expression.Call(
                               _getRelatedValueReadersMethodInfo,
                               QueryContextParameter,
                               Expression.Constant(targetType),
                               primaryKeyParameter,
                               relatedKeyFactoryParameter,
                               materializer),
                           primaryKeyParameter,
                           relatedKeyFactoryParameter));
            })),
                      Expression.Constant(querySourceRequiresTracking));
        }
            protected override Expression VisitEntityQueryable(Type elementType)
            {
                Check.NotNull(elementType, nameof(elementType));

                var entityType
                    = QueryModelVisitor.QueryCompilationContext.Model
                      .GetEntityType(elementType);

                var keyProperties
                    = entityType.GetPrimaryKey().Properties;

                var keyFactory
                    = QueryModelVisitor
                      .QueryCompilationContext
                      .EntityKeyFactorySource.GetKeyFactory(entityType.GetPrimaryKey());

                Func <ValueBuffer, EntityKey> entityKeyFactory
                    = vr => keyFactory.Create(keyProperties, vr);

                if (QueryModelVisitor.QueryCompilationContext
                    .QuerySourceRequiresMaterialization(_querySource))
                {
                    var materializer
                        = new MaterializerFactory(QueryModelVisitor
                                                  .QueryCompilationContext
                                                  .EntityMaterializerSource)
                          .CreateMaterializer(entityType);

                    return(Expression.Call(
                               _entityQueryMethodInfo.MakeGenericMethod(elementType),
                               QueryContextParameter,
                               Expression.Constant(entityType),
                               Expression.Constant(entityKeyFactory),
                               materializer,
                               Expression.Constant(QueryModelVisitor.QuerySourceRequiresTracking(_querySource))));
                }

                return(Expression.Call(
                           _projectionQueryMethodInfo,
                           QueryContextParameter,
                           Expression.Constant(entityType)));
            }