예제 #1
0
        private ODataQueryCriteria Desrialize(IValueProvider values)
        {
            var criteria = new ODataQueryCriteria();

            var orderBy = values.GetValue("$orderby");

            if (orderBy != null)
            {
                criteria.OrderBy = orderBy.AttemptedValue;
            }

            var filter = values.GetValue("$filter");

            if (filter != null)
            {
                criteria.Filter = filter.AttemptedValue;
            }

            ParsePagingInfo(values, criteria);

            var expand = values.GetValue("$expand");

            if (expand != null)
            {
                criteria.Expand = expand.AttemptedValue;
            }

            return(criteria);
        }
예제 #2
0
        private static void ParsePagingInfo(IValueProvider values, ODataQueryCriteria criteria)
        {
            var pn = values.GetValue("$pageNumber");
            var tc = values.GetValue("$inlinecount");

            if (pn != null || tc != null)
            {
                var pageNumber = pn != null ? (int)pn.ConvertTo(typeof(int)) : 1;
                var needCount  = tc != null && !string.IsNullOrWhiteSpace(tc.AttemptedValue);

                var ps       = values.GetValue("$pageSize");
                int pageSize = ps != null ? (int)ps.ConvertTo(typeof(int)) : 10;

                var pagingInfo = new PagingInfo(pageNumber, pageSize, needCount);
                criteria.PagingInfo = pagingInfo;
            }
        }
예제 #3
0
        //[HttpGet]
        //public object GetAll()
        //{
        //    return Repo.GetAll();
        //}

        protected object Get(ODataQueryCriteria criteria)
        {
            return(_repo.GetBy(criteria));
        }
예제 #4
0
        protected EntityList FetchBy(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));
        }
예제 #5
0
 public static EntityList GetByOData(EntityRepository repository, ODataQueryCriteria criteria)
 {
     return(FetchList(repository, criteria));
 }