Beispiel #1
0
        IEnumerable <T> Run(IEnumerable <object> ids)
        {
            var hql = "from " + Type.FullName + " _this ";

            if (ids.HasItems())
            {
                hql += " where _this." + Metadata.IdentifierPropertyName + " in (" + string.Join(",", ids) + ")";
            }
            hql += DoOrderby ? GenerateOrderByString() : string.Empty;

            var hasmanys = Fetch.Where(f => Metadata.PropertyNames.Contains(f) && Metadata.GetPropertyType(f) is CollectionType);

            if (hasmanys.HasItems())
            {
                var q = new DetachedQuery("select _this.Id " + hql);
                if (PageSize != 0)
                {
                    q.SetMaxResults(PageSize).SetFirstResult(PageSize * (Page - 1));
                }
                var fetchids = q.List <T, object>();

                if (fetchids.HasItems())
                {
                    foreach (var f in hasmanys)
                    {
                        var fetchhql = "from " + Type.FullName + " _that ";
                        fetchhql += "left join fetch _that." + f;
                        fetchhql += " where _that." + Metadata.IdentifierPropertyName + " in ( " + string.Join(",", fetchids) + " )";
                        new DetachedQuery(fetchhql).Future <T>();
                    }
                }
            }

            return(RunItemsWithBelongsFetch(ids));
        }
Beispiel #2
0
        IEnumerable <T> RunItemsWithBelongsFetch(IEnumerable <object> ids)
        {
            var belongs = Fetch.Where(f => Metadata.PropertyNames.Contains(f) && Metadata.GetPropertyType(f) is EntityType);
            var hql     = "from " + Type.FullName + " _this ";

            hql += belongs.Select(f => " left join fetch _this." + f).Join(" ");
            if (ids.HasItems())
            {
                hql += " where _this." + Metadata.IdentifierPropertyName + " in (" + string.Join(",", ids) + ")";
            }
            hql += GenerateOrderByString();
            var q = new DetachedQuery(hql);

            if (PageSize != 0)
            {
                q.SetMaxResults(PageSize).SetFirstResult(PageSize * (Page - 1));
            }
            return(q.Future <T>());
        }