Ejemplo n.º 1
0
        /// <summary>
        /// This Prefetch call is a simpler API for when you are not interested in tweaking the Query
        /// </summary>
        /// <param name="maps">The Path to the data</param>
        public void Prefetch(params tgPrefetchMap[] maps)
        {
            if (maps != null)
            {
                if (prefetchMaps == null)
                {
                    prefetchMaps = new List <tgPrefetchMap>();
                }

                tgPrefetchParameters data = new tgPrefetchParameters();

                // Create the query, we do so in reverse order
                for (int i = maps.Length - 1; i >= 0; i--)
                {
                    tgPrefetchDelegate prefetchDelegate = maps[i].PrefetchDelegate;
                    prefetchDelegate(data);
                }

                // The path is the next to the last PropertyName
                string path = string.Empty;
                if (maps.Length > 1)
                {
                    path = maps[maps.Length - 2].PropertyName;
                }

                tgPrefetchMap rootMap = maps[maps.Length - 1];
                rootMap.Query = data.Root;
                rootMap.Path  = path;
                prefetchMaps.Add(rootMap);

                rootMap.Query.Select(rootMap.Query);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This Prefetch allows you to fill in the Select() statement for the query to control what columns are brought back
        /// </summary>
        /// <typeparam name="T">The Type of the esDynamicQuery returned</typeparam>
        /// <param name="provideSelect">If true then you must fill in the Query.Select() clause</param>
        /// <param name="maps">The Path to the data</param>
        /// <returns>The esDynamicQuery for the Type of query you intend to load</returns>
        public T Prefetch <T>(bool provideSelect, params tgPrefetchMap[] maps) where T : tgDynamicQuery
        {
            if (maps != null)
            {
                if (prefetchMaps == null)
                {
                    prefetchMaps = new List <tgPrefetchMap>();
                }

                tgPrefetchParameters data = new tgPrefetchParameters();

                // Create the query, we do so in reverse order
                for (int i = maps.Length - 1; i >= 0; i--)
                {
                    tgPrefetchDelegate prefetchDelegate = maps[i].PrefetchDelegate;
                    prefetchDelegate(data);
                }

                // The path is the next to the last PropertyName
                string path = string.Empty;
                if (maps.Length > 1)
                {
                    path = maps[maps.Length - 2].PropertyName;
                }

                tgPrefetchMap rootMap = maps[maps.Length - 1];
                rootMap.Query = data.Root;
                rootMap.Path  = path;
                prefetchMaps.Add(rootMap);

                if (provideSelect)
                {
                    rootMap.Query.Select(rootMap.Query);
                }

                return((T)data.Root);
            }

            return(null);
        }