예제 #1
0
        public ServicePredicateBuilder <TDestination> Cast <TDestination>() where TDestination : class
        {
            var result = new ServicePredicateBuilder <TDestination>();

            if (IncludedNavigationProperties != null && IncludedNavigationProperties.Count > 0)
            {
                result.IncludedNavigationProperties = new List <string>();
                foreach (var includedNavigationProperty in IncludedNavigationProperties)
                {
                    var stringBuilder = new StringBuilder(includedNavigationProperty);
                    result.IncludedNavigationProperties.Add(stringBuilder.ToString());
                }
            }

            if (PaginationData != null)
            {
                result.PaginationData = new PaginationData
                {
                    ItemsPerPage = PaginationData.ItemsPerPage,
                    PageNumber   = PaginationData.PageNumber
                };
            }

            result.Criteria = Criteria.Cast <TDestination>();
            if (SortCondition != null)
            {
                result.SortCondition = SortCondition.Cast <TDestination>();
            }

            return(result);
        }
예제 #2
0
        private static ExpressionInfo <TEntity> GetExpressionInfoFromPredicateBuilder(ServicePredicateBuilder <TEntity> servicePredicateBuilder)
        {
            if (servicePredicateBuilder == null)
            {
                return(null);
            }
            var result = new ExpressionInfo <TEntity>();

            if (servicePredicateBuilder.Criteria != null)
            {
                result.Expression = servicePredicateBuilder.Criteria.GetExpression();
            }
            if (servicePredicateBuilder.PaginationData != null)
            {
                result.PaginationData = new PaginationData
                {
                    ItemsPerPage = servicePredicateBuilder.PaginationData.ItemsPerPage,
                    PageNumber   = servicePredicateBuilder.PaginationData.PageNumber
                };
            }

            if (servicePredicateBuilder.IncludedNavigationProperties != null && servicePredicateBuilder.IncludedNavigationProperties.Any())
            {
                result.IncludedNavigationProperties = new List <string>();
                foreach (var navigation in servicePredicateBuilder.IncludedNavigationProperties)
                {
                    result.IncludedNavigationProperties.Add(navigation);
                }
            }

            if (servicePredicateBuilder.SortCondition != null)
            {
                result.SortCondition = SortCondition <TEntity> .None();

                result.SortCondition.SetSortItems(servicePredicateBuilder.SortCondition.GetSortItems());
            }

            return(result);
        }