Ejemplo n.º 1
0
        public void TestWhere_Criteria()
        {
            _query.Where(new CriteriaSample());
            Assert.Equal("t => ((t.Name == \"A\") AndAlso (t.Tel == 1))", _query.GetPredicate().ToString());

            _query = new Query <AggregateRootSample>();
            _query.Where(new DefaultCriteria <AggregateRootSample>(t => t.Name == null));
            Assert.NotNull(_query.GetPredicate());
        }
Ejemplo n.º 2
0
        public TEntity GetSingle(IExpressionQuery <TEntity> queryCriteria)
        {
            if (queryCriteria != null)
            {
                var resultList = queryCriteria.Execute(Set).FirstOrDefault();
                return(resultList);
            }

            return(FirstOrDefault());
        }
Ejemplo n.º 3
0
        public IEnumerable <TEntity> GetList(IExpressionQuery <TEntity> queryCriteria)
        {
            if (queryCriteria != null)
            {
                var predicate = queryCriteria.BuildExpression();
                return(GetList(predicate));
            }

            return(GetList());
        }
Ejemplo n.º 4
0
        public static IQueryable <T> LoadWith <T>(
            [NotNull] this IExpressionQuery <T> table,
            [NotNull, InstantHandle] Expression <Func <T, object> > selector)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            table.Expression = GetExpressionLoadWith(table.Expression, selector);

            return(table);
        }
Ejemplo n.º 5
0
        public void TestOrderBy()
        {
            QueryParameterSample sample = new QueryParameterSample {
                Order = "Name"
            };

            _query = new Query <AggregateRootSample>(sample);
            Assert.Equal("Name", _query.GetOrder());

            _query.OrderBy("Age", true);
            Assert.Equal("Name,Age desc", _query.GetOrder());

            _query.OrderBy(t => t.Tel, true);
            Assert.Equal("Name,Age desc,Tel desc", _query.GetOrder());
        }
Ejemplo n.º 6
0
        public void TestWhere()
        {
            _query.Where(t => t.Name == "A");
            Assert.Equal("t => (t.Name == \"A\")", ZKCloud.Extensions.Extensions.SafeString(_query.GetPredicate()));

            _query.Where(t => t.Tel == 1);
            Assert.Equal("t => ((t.Name == \"A\") AndAlso (t.Tel == 1))", ZKCloud.Extensions.Extensions.SafeString(_query.GetPredicate()));

            _query = new Query <AggregateRootSample>();
            _query.Where(t => t.Name == "A" && t.Tel == 1);
            Assert.Equal("t => ((t.Name == \"A\") AndAlso (t.Tel == 1))", ZKCloud.Extensions.Extensions.SafeString(_query.GetPredicate()));

            _query = new Query <AggregateRootSample>();
            _query.Where(t => t.Name == "");
            Assert.NotNull(_query.GetPredicate());
        }
Ejemplo n.º 7
0
        public void TestGetPager()
        {
            QueryParameterSample sample = new QueryParameterSample()
            {
                Order      = "A",
                Page       = 2,
                PageSize   = 30,
                TotalCount = 40
            };

            _query = new Query <AggregateRootSample>(sample);
            _query.OrderBy("B", true);
            var pager = _query.GetPager();

            Assert.Equal(2, pager.Page);
            Assert.Equal(30, pager.PageSize);
            Assert.Equal(40, pager.TotalCount);
            Assert.Equal("A,B desc", pager.Order);
        }
Ejemplo n.º 8
0
 private static void InitParameters <T>(IExpressionQuery eq, Query <T> info, Expression expression)
 {
     eq.DataContext.GetQueryRunner(info, 0, expression, null, null).GetSqlText();
 }
Ejemplo n.º 9
0
 public TEntity GetSingle(IExpressionQuery <TEntity> query)
 {
     return(Store.GetSingle(query));
 }
Ejemplo n.º 10
0
 public async Task <IEnumerable <TEntity> > GetListAsync(IExpressionQuery <TEntity> query)
 {
     // return await Store.GetList(query).ToList();
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public IList <TEntity> GetList(IExpressionQuery <TEntity> queryCriteria)
 {
     return(Store.GetList(queryCriteria).ToList());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// This is internal API and is not intended for use by Linq To DB applications.
 /// It may change or be removed without further notice.
 /// </summary>
 public static IDataContext GetDataContext <T>(IQueryable <T> queryable)
 {
     return(queryable switch
     {
         IExpressionQuery query => query.DataContext,
         _ => default !,