Пример #1
0
 private EntityList FetchBy(ODataQueryCriteria criteria)
 {
     return(this.GetBy(criteria));
 }
Пример #2
0
        /// <summary>
        /// <see cref="ODataQueryCriteria"/> 查询的数据层实现。
        /// </summary>
        /// <param name="criteria"></param>
        public virtual EntityList GetBy(ODataQueryCriteria criteria)
        {
            var t = f.Table(this.Repository);

            var q = f.Query(from: t);

            var properties = this.Repository.EntityMeta.ManagedProperties.GetCompiledProperties();

            #region Filter

            if (!string.IsNullOrWhiteSpace(criteria.Filter))
            {
                var parser = new ODataFilterParser
                {
                    _properties = properties
                };
                parser.Parse(criteria.Filter, q);
            }

            #endregion

            #region OrderBy

            if (!string.IsNullOrWhiteSpace(criteria.OrderBy))
            {
                var orderByProperties = criteria.OrderBy.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var orderByExp in orderByProperties)
                {
                    var values   = orderByExp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var property = values[0];
                    var orderBy  = properties.Find(property, true);
                    if (orderBy != null)
                    {
                        var dir = values.Length == 1 || values[1].ToLower() == "asc" ? OrderDirection.Ascending : OrderDirection.Descending;
                        q.OrderBy.Add(f.OrderBy(t.Column(orderBy), dir));
                    }
                }
            }

            #endregion

            #region Expand

            if (!string.IsNullOrWhiteSpace(criteria.Expand))
            {
                var eagerLoad = new EagerLoadOptions();

                var expandProperties = criteria.Expand.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                var splitter         = new char[] { '.' };
                foreach (var expand in expandProperties)
                {
                    //如果有'.',表示类似于 Section.Chapter.Book 这种表达式。
                    if (expand.Contains('.'))
                    {
                        Type nextEntityType = null;//下一个需要使用的实体类型

                        var cascadeProperties = expand.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var property in cascadeProperties)
                        {
                            var container = properties;
                            if (nextEntityType != null)
                            {
                                var meta = CommonModel.Entities.Find(nextEntityType);
                                container = meta.ManagedProperties.GetCompiledProperties();
                            }

                            var mp = container.Find(property, true);
                            if (mp != null)
                            {
                                var refProperty = mp as IRefEntityProperty;
                                if (refProperty != null)
                                {
                                    eagerLoad.LoadWith(refProperty);
                                    nextEntityType = refProperty.RefEntityType;
                                }
                                else if (mp is IListProperty)
                                {
                                    eagerLoad.LoadWith(mp as IListProperty);
                                    nextEntityType = (mp as IListProperty).ListEntityType;
                                }
                            }
                        }
                    }
                    else
                    {
                        var mp = properties.Find(expand, true);
                        if (mp != null)
                        {
                            if (mp is IListProperty)
                            {
                                eagerLoad.LoadWith(mp as IListProperty);
                            }
                            else if (mp is IRefEntityProperty)
                            {
                                eagerLoad.LoadWith(mp as IRefEntityProperty);
                            }
                        }
                        else if (expand == EntityConvention.TreeChildrenPropertyName)
                        {
                            eagerLoad.LoadWithTreeChildren();
                        }
                    }

                    criteria.EagerLoad = eagerLoad;
                }
            }

            #endregion

            return(this.QueryList(q, criteria.PagingInfo, criteria.EagerLoad));
        }
Пример #3
0
 /// <summary>
 /// 通过 <see cref="ODataQueryCriteria"/> 来查询实体列表。
 /// </summary>
 /// <param name="criteria">常用查询条件。</param>
 /// <returns></returns>
 public EntityList GetBy(ODataQueryCriteria criteria)
 {
     return(this.DoGetBy(criteria));
 }
Пример #4
0
 /// <summary>
 /// 通过 <see cref="ODataQueryCriteria"/> 来查询实体列表。
 /// </summary>
 /// <param name="criteria">常用查询条件。</param>
 /// <returns></returns>
 protected virtual EntityList DoGetBy(ODataQueryCriteria criteria)
 {
     return(this.FetchList(criteria));
 }
Пример #5
0
 protected virtual long DoCountBy(ODataQueryCriteria criteria)
 {
     return((long)_dataProvider.GetBy(criteria));
 }
Пример #6
0
        /// <summary>
        /// <see cref="ODataQueryCriteria"/> 查询的数据层实现。
        /// </summary>
        /// <param name="criteria"></param>
        public virtual EntityList GetBy(ODataQueryCriteria criteria)
        {
            var f = QueryFactory.Instance;
            var t = f.Table(this.Repository);

            var q = f.Query(from: t);

            var properties = this.Repository.EntityMeta.ManagedProperties.GetCompiledProperties();

            //filter
            if (!string.IsNullOrWhiteSpace(criteria.Filter))
            {
                var parser = new ODataFilterParser
                {
                    _mainTable  = t,
                    _properties = properties
                };
                q.Where = parser.Parse(criteria.Filter);
            }

            //order by
            if (!string.IsNullOrWhiteSpace(criteria.OrderBy))
            {
                var orderByProperties = criteria.OrderBy.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var orderByExp in orderByProperties)
                {
                    var values   = orderByExp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var property = values[0];
                    var orderBy  = properties.Find(property, true);
                    if (orderBy != null)
                    {
                        var dir = values.Length == 1 || values[1].ToLower() == "asc" ? OrderDirection.Ascending : OrderDirection.Descending;
                        q.OrderBy.Add(f.OrderBy(t.Column(orderBy), dir));
                    }
                }
            }

            //expand
            if (!string.IsNullOrWhiteSpace(criteria.Expand))
            {
                criteria.EagerLoad = new EagerLoadOptions();

                var expandProperties = criteria.Expand.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var expand in expandProperties)
                {
                    var mp = properties.Find(expand, true);
                    if (mp != null)
                    {
                        if (mp is IListProperty)
                        {
                            criteria.EagerLoad.LoadWith(mp as IListProperty);
                        }
                        else if (mp is IRefEntityProperty)
                        {
                            criteria.EagerLoad.LoadWith(mp as IRefEntityProperty);
                        }
                    }
                }
            }

            return(this.QueryList(q, criteria.PagingInfo, criteria.EagerLoad));
        }
Пример #7
0
 protected virtual Entity DoGetFirstBy(ODataQueryCriteria criteria)
 {
     return((Entity)_dataProvider.GetBy(criteria));
 }
Пример #8
0
 /// <summary>
 /// 通过 <see cref="ODataQueryCriteria"/> 来查询实体的个数。
 /// </summary>
 /// <param name="criteria">常用查询条件。</param>
 /// <returns></returns>
 public long CountBy(ODataQueryCriteria criteria)
 {
     return(this.DoCountBy(criteria));
 }
Пример #9
0
 /// <summary>
 /// 通过 <see cref="ODataQueryCriteria"/> 来查询某个实体。
 /// </summary>
 /// <param name="criteria">常用查询条件。</param>
 /// <returns></returns>
 public Entity GetFirstBy(ODataQueryCriteria criteria)
 {
     return(this.DoGetFirstBy(criteria));
 }
Пример #10
0
 protected virtual int DoCountBy(ODataQueryCriteria criteria)
 {
     return((int)_dataProvider.GetBy(criteria));
 }
Пример #11
0
 private static TestUserList QueryUserList(ODataQueryCriteria criteria)
 {
     return RF.Concrete<TestUserRepository>().GetBy(criteria) as TestUserList;
 }