private static IEnumerable <T> handleIncludes <T>(Query query, IEnumerable <T> result)
        {
            if (!result.Any())
            {
                return(result);
            }

            bool canBeProcessed = query.Includes.Any() && result.ElementAt(0) is IDynamicMetaObjectProvider;

            if (!canBeProcessed)
            {
                return(result);
            }
            List <Dictionary <string, object> > dynamicResult = QueryFactoryHelper.GetDynamicResult(result);

            foreach (Include include in query.Includes)
            {
                processManyIncludeStatements(query, dynamicResult, include);

                if (include.ForeignKey == null)
                {
                    include.ForeignKey = include.Name + "Id";
                }
                List <string> foreignIds = QueryFactoryHelper.GetForeignIDs(dynamicResult, include);

                processManyForeignIDs(dynamicResult, include, foreignIds);
            }

            return(dynamicResult.Cast <T>());
        }
        private static void processManyIncludeStatements(Query query, List <Dictionary <string, object> > dynamicResult, Include include)
        {
            if (include.IsMany)
            {
                QueryFactoryHelper.TryFetchingForeignKey(query, include);
                List <object> localIds = QueryFactoryHelper.GetLocalIDs(dynamicResult, include);

                if (localIds.Any())
                {
                    Dictionary <string, List <Dictionary <string, object> > > children = getEmbeddedIncludesSync(include, localIds);

                    foreach (var item in dynamicResult)
                    {
                        var localValue = item[include.LocalKey].ToString();
                        item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : new List <Dictionary <string, object> >();
                    }
                }
            }
        }