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)); }
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); }
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); }
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); }
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()); }
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); }
// 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}]"); } }
public static TEntity First <TEntity, TParameter>(this ILtConnection _this, QueryFluent <TEntity> query, TParameter values) => _this.First(query.ToImmutable(), values);
public static TEntity First <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query) => _this.First(query.ToImmutable());
public static TEntity Single <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query) => _this.Single(query.ToImmutable());
public static IEnumerable <TEntity> Select <TEntity, TParameter>(this ILtConnection _this, QueryFluent <TEntity> query, TParameter values) => _this.Select(query.ToImmutable(), values);
public static IEnumerable <TEntity> Select <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query) => _this.Select(query.ToImmutable());
public static int Count <TEntity>(this ILtConnection _this, QueryFluent <TEntity> query) => _this.Count(query.ToImmutable());
public static QueryFluent <TEntity> ThenByDescending <TEntity, TProperty>(this QueryFluent <TEntity> _this, Expression <Func <TEntity, TProperty> > selector) => _this.ThenByDescending(getProperty(selector).Name);
// OrderBy/ThenBy public static QueryFluent <TEntity> OrderBy <TEntity, TProperty>(this QueryFluent <TEntity> _this, Expression <Func <TEntity, TProperty> > selector) => _this.OrderBy(getProperty(selector).Name);