コード例 #1
0
ファイル: RepositoryExtensions.cs プロジェクト: cuongdn/mmisc
 public static IPagedList <T> GetPaged <T>(this QueryFluent <T> query, GridRequest request)
     where T : EntityBase
 {
     return(query.Where(request.GetFilters <T>())
            .OrderBy(request.GetSortExpression())
            .Paged(request.Page, request.PageSize));
 }
コード例 #2
0
        public void QuerySelectOrderByExpressionTestClan()
        {
            _query = new QueryFluent <NinjaClan>(new Repository <NinjaClan>(_ninjaClanFakeContext, _unitOfWorkAsync), new AllNinjaExpressionSpecification());

            var ninjaClan = _query.OrderBy(x => x.OrderBy(clan => clan.ClanName)).Select().First();

            Assert.AreEqual("AnotherClan", ninjaClan.ClanName);
        }
コード例 #3
0
        public void QuerySelectAndPageTestClan()
        {
            _query = new QueryFluent <NinjaClan>(new Repository <NinjaClan>(_ninjaClanFakeContext, _unitOfWorkAsync), new AllNinjaExpressionSpecification());

            var ninjaClans = _query.SelectPage(1, 1, out var totalCount).ToList();

            Assert.AreEqual(2, totalCount);
            Assert.AreEqual(1, ninjaClans.Count);
        }
コード例 #4
0
        public void QuerySelectOrderByAndIncludeTestClan()
        {
            _query = new QueryFluent <NinjaClan>(new Repository <NinjaClan>(_ninjaClanFakeContext, _unitOfWorkAsync), new AllNinjaExpressionSpecification());

            var ninjaEquipmentOwned = _query.Include(clan => clan.Ninjas).Select().First().Ninjas.First().EquipmentOwned;

            Assert.IsNotNull(ninjaEquipmentOwned);
            Assert.AreEqual(3, ninjaEquipmentOwned.Count);
        }
コード例 #5
0
        public void QuerySelectExpressionTestClan()
        {
            _query = new QueryFluent <NinjaClan>(new Repository <NinjaClan>(_ninjaClanFakeContext, _unitOfWorkAsync), new AllNinjaExpressionSpecification());

            var ninjaClan = _query.Select(x => x.ClanName).ToList();

            Assert.AreEqual(2, ninjaClan.Count);
            Assert.AreEqual("TestClan", ninjaClan.First());
        }
コード例 #6
0
        public void QuerySelectTestClan()
        {
            _query = new QueryFluent <NinjaClan>(new Repository <NinjaClan>(_ninjaClanFakeContext, _unitOfWorkAsync), new AllNinjaExpressionSpecification());

            var ninjaClan = _query.Select().ToList();

            Assert.AreEqual(2, ninjaClan.Count);
            Assert.AreEqual(1, ninjaClan.First().Ninjas.Count);
            Assert.AreEqual(3, ninjaClan.First().Ninjas.First().EquipmentOwned.Count);
        }
コード例 #7
0
        // Where
        public static QueryFluent <TEntity> Where <TEntity>(this QueryFluent <TEntity> _this, Expression <Func <TEntity, bool> > predicate)
        {
            var body = predicate.Body;

            switch (body)
            {
            case BinaryExpression binary:
                var left = binary.Left as MemberExpression ?? throw new ArgumentException("Lhs must be PropertyAccess", nameof(predicate));

                // Usually MethodCallExpression is passed.
                // Sometimes UnaryExpression is passed even though the same syntax.
                MethodCallExpression right;
                switch (binary.Right)
                {
                case MethodCallExpression methodExp:
                    right = methodExp;
                    break;

                case UnaryExpression unaryExp:
                    right = unaryExp.Operand as MethodCallExpression ?? throw new ArgumentException("Rhs must be Lt.Arg<>()", nameof(predicate));
                    break;

                default:
                    throw new ArgumentException("Rhs must be Lt.Arg<>()", nameof(predicate));
                }

                string parameterName;
                if (right.Arguments.Count == 0)
                {
                    parameterName = left.Member.Name;
                }
                else
                {
                    var arg = right.Arguments[0] as ConstantExpression ?? throw new ArgumentException("Rhs must be Lt.Arg<>()", nameof(predicate));
                    parameterName = (string)arg.Value ?? throw new ArgumentException("Lt.Arg<>() argment must not null", nameof(predicate));
                }

                switch (binary.NodeType)
                {
                case ExpressionType.Equal:
                    return(_this.Where(new EqualOperator(new Property <TEntity>(left.Member.Name), new Parameter(parameterName))));

                default:
                    throw new NotSupportedException($"not supported convert [{binary.NodeType}]");
                }

            default:
                throw new NotSupportedException($"not supported [{body}]");
            }
        }
コード例 #8
0
 public static TEntity First <TEntity, TParameter>(this ILtConnection _this, QueryFluent <TEntity> query, TParameter values)
 => _this.First(query.ToImmutable(), values);
コード例 #9
0
 public static TEntity First <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query)
 => _this.First(query.ToImmutable());
コード例 #10
0
 public static TEntity Single <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query)
 => _this.Single(query.ToImmutable());
コード例 #11
0
 public static IEnumerable <TEntity> Select <TEntity, TParameter>(this ILtConnection _this, QueryFluent <TEntity> query, TParameter values)
 => _this.Select(query.ToImmutable(), values);
コード例 #12
0
 public static IEnumerable <TEntity> Select <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query)
 => _this.Select(query.ToImmutable());
コード例 #13
0
 public static int Count <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query)
 => _this.Count(query.ToImmutable());
コード例 #14
0
 public static QueryFluent <TEntity> ThenByDescending <TEntity, TProperty>(this QueryFluent <TEntity> _this, Expression <Func <TEntity, TProperty> > selector)
 => _this.ThenByDescending(getProperty(selector).Name);
コード例 #15
0
 // OrderBy/ThenBy
 public static QueryFluent <TEntity> OrderBy <TEntity, TProperty>(this QueryFluent <TEntity> _this, Expression <Func <TEntity, TProperty> > selector)
 => _this.OrderBy(getProperty(selector).Name);