Example #1
0
        /// <summary>
        /// Performs expands based on the list of strings.
        /// Also populates the ExpandTypeMap that controls lazy initialization and serialization.
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="expands"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        protected IQueryable ApplyExpansions(IQueryable queryable, IList <string> expands, HttpRequestMessage request)
        {
            var expandMap = GetRequestProperty(request, EXPAND_MAP_KEY) as ExpandTypeMap;

            if (expandMap == null)
            {
                expandMap = new ExpandTypeMap();
            }

            var session = GetRequestProperty(request, NH_SESSION_KEY) as ISession;

            if (queryable == null)
            {
                throw new Exception("Query cannot be null");
            }

            var fetcher = new NHEagerFetch(session.SessionFactory);

            queryable = fetcher.ApplyExpansions(queryable, expands.ToArray(), expandMap);

            if (!request.Properties.ContainsKey(EXPAND_MAP_KEY))
            {
                request.Properties.Add(EXPAND_MAP_KEY, expandMap);
            }

            return(queryable);
        }
Example #2
0
        /// <summary>
        /// Overrides the method in QueryHelper to perform the $expands in NHibernate.
        /// Also populates the ExpandTypeMap that controls lazy initialization and serialization.
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="expandsQueryString"></param>
        /// <returns></returns>
        public override IQueryable ApplyExpand(IQueryable queryable, string expandsQueryString)
        {
            if (string.IsNullOrWhiteSpace(expandsQueryString)) return queryable;
            var session = GetSession(queryable);
            var fetcher = new NHEagerFetch(session.SessionFactory);
            queryable = fetcher.ApplyExpansions(queryable, expandsQueryString, expandMap);

            return queryable;
        }
Example #3
0
        /// <summary>
        /// Performs expands based on the list of strings in queryable.GetIncludes().
        /// Also populates the ExpandTypeMap that controls lazy initialization and serialization.
        /// </summary>
        /// <param name="queryable"></param>
        /// <returns></returns>
        public IQueryable ApplyExpand(IQueryableInclude queryable)
        {
            var expands = queryable.GetIncludes();
            if (expands == null || expands.Count == 0) return queryable;
            var session = GetSession(queryable);
            var fetcher = new NHEagerFetch(session.SessionFactory);
            var expandedQueryable = fetcher.ApplyExpansions(queryable, expands.ToArray(), expandMap);

            return expandedQueryable;
        }
Example #4
0
        /// <summary>
        /// Recursively forces loading of each NHibernate proxy in the tree that matches an entry in the map.
        /// </summary>
        /// <param name="list">Top-level collection of objects</param>
        /// <param name="expandMap">Properties to initialize for each type</param>
        public static void InitializeList <T>(IEnumerable <T> list, params string[] expandPaths)
        {
            var expandMap = NHEagerFetch.MapExpansions(typeof(T), expandPaths);

            var map   = expandMap.map;
            var depth = expandMap.maxDepth;

            foreach (var el in list)
            {
                InitializeWithCascade(el, map, depth);
            }
        }
Example #5
0
        /// <summary>
        /// Overrides the method in QueryHelper to perform the $expands in NHibernate.
        /// Also populates the ExpandTypeMap that controls lazy initialization and serialization.
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="expandsQueryString"></param>
        /// <returns></returns>
        public override IQueryable ApplyExpand(IQueryable queryable, string expandsQueryString)
        {
            if (string.IsNullOrWhiteSpace(expandsQueryString))
            {
                return(queryable);
            }
            var session = GetSession(queryable);
            var fetcher = new NHEagerFetch(session.SessionFactory);

            queryable = fetcher.ApplyExpansions(queryable, expandsQueryString, expandMap);

            return(queryable);
        }
Example #6
0
        /// <summary>
        /// Performs expands based on the list of strings in queryable.GetIncludes().
        /// Also populates the ExpandTypeMap that controls lazy initialization and serialization.
        /// </summary>
        /// <param name="queryable"></param>
        /// <returns></returns>
        public IQueryable ApplyExpand(IQueryableInclude queryable)
        {
            var expands = queryable.GetIncludes();

            if (expands == null || expands.Count == 0)
            {
                return(queryable);
            }
            var session           = GetSession(queryable);
            var fetcher           = new NHEagerFetch(session.SessionFactory);
            var expandedQueryable = fetcher.ApplyExpansions(queryable, expands.ToArray(), expandMap);

            return(expandedQueryable);
        }
Example #7
0
        /// <summary>
        /// Calls NHEagerFetch.ApplyExpansions
        /// </summary>
        /// <param name="queryable">The query to expand</param>
        /// <param name="expandsQueryString">value of the $expand query parameter</param>
        /// <param name="expandMap">Empty dictionary that will be populated with the names of the expanded properties for each type.</param>
        /// <returns></returns>
        protected IQueryable ApplyExpansions(IQueryable queryable, string expandsQueryString, ExpandTypeMap expandMap, ISessionFactory sessionFactory)
        {
            if (string.IsNullOrWhiteSpace(expandsQueryString))
            {
                return(queryable);
            }

            string[] expandPaths = expandsQueryString.Split(',').Select(s => s.Trim()).ToArray();
            if (!expandPaths.Any())
            {
                throw new Exception("Expansion Paths cannot be null");
            }
            if (queryable == null)
            {
                throw new Exception("Query cannot be null");
            }

            var fetcher = new NHEagerFetch(sessionFactory);

            return(fetcher.ApplyExpansions(queryable, expandPaths, expandMap));
        }
        /// <summary>
        /// Calls NHEagerFetch.ApplyExpansions
        /// </summary>
        /// <param name="queryable">The query to expand</param>
        /// <param name="expandsQueryString">value of the $expand query parameter</param>
        /// <param name="expandMap">Empty dictionary that will be populated with the names of the expanded properties for each type.</param>
        /// <returns></returns>
        protected IQueryable ApplyExpansions(IQueryable queryable, string expandsQueryString, ExpandTypeMap expandMap, ISessionFactory sessionFactory)
        {
            if (string.IsNullOrWhiteSpace(expandsQueryString))
            {
                return queryable;
            }

            string[] expandPaths = expandsQueryString.Split(',').Select(s => s.Trim()).ToArray();
            if (!expandPaths.Any()) throw new Exception("Expansion Paths cannot be null");
            if (queryable == null) throw new Exception("Query cannot be null");

            var fetcher = new NHEagerFetch(sessionFactory);
            return fetcher.ApplyExpansions(queryable, expandPaths, expandMap);
        }
        /// <summary>
        /// Performs expands based on the list of strings.
        /// Also populates the ExpandTypeMap that controls lazy initialization and serialization.
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="expands"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        protected IQueryable ApplyExpansions(IQueryable queryable, IList<string> expands, HttpRequestMessage request)
        {
            var expandMap = GetRequestProperty(request, EXPAND_MAP_KEY) as ExpandTypeMap;
            if (expandMap == null) expandMap = new ExpandTypeMap();

            var session = GetRequestProperty(request, NH_SESSION_KEY) as ISession;
            if (queryable == null) throw new Exception("Query cannot be null");

            var fetcher = new NHEagerFetch(session.SessionFactory);
            queryable = fetcher.ApplyExpansions(queryable, expands.ToArray(), expandMap);

            if (!request.Properties.ContainsKey(EXPAND_MAP_KEY))
                request.Properties.Add(EXPAND_MAP_KEY, expandMap);

            return queryable;
        }