Exemplo n.º 1
0
 public IQueryable <TEntity> GetModel(System.Linq.Expressions.Expression <Func <TEntity, bool> > predicate)
 {
     return(GetModel().Where(predicate));
 }
Exemplo n.º 2
0
 public List <human_file> FindAllHumanFileByState(int pageInxex, int pageSize, out int count, System.Linq.Expressions.Expression <Func <human_file, bool> > where)
 {
     return(dao.FindAllHumanFileByState(pageInxex, pageSize, out count, where));
 }
Exemplo n.º 3
0
 public IEnumerable <T> Get(System.Linq.Expressions.Expression <Func <T, bool> > predicate)
 {
     return(_unitOfWork.Context.Set <T>().Where(predicate).AsEnumerable <T>());
 }
        protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder)
        {
            var dbQuery = this._efContext.Context.Set <TAggregateRoot>()
                          .Where(specification.IsSatisfiedBy);

            if (sortPredicate != null)
            {
                switch (sortOrder)
                {
                case SortOrder.Ascending:
                    return(dbQuery.OrderBy(sortPredicate.Compile()).ToList());

                case SortOrder.Descending:
                    return(dbQuery.OrderByDescending(sortPredicate.Compile()).ToList());

                default:
                    break;
                }
            }

            return(dbQuery.ToList());
        }
Exemplo n.º 5
0
        public SystemCountryCodePoco GetSingle(System.Linq.Expressions.Expression <Func <SystemCountryCodePoco, bool> > where, params System.Linq.Expressions.Expression <Func <SystemCountryCodePoco, object> >[] navigationProperties)
        {
            IQueryable <SystemCountryCodePoco> pocos = GetAll().AsQueryable();

            return(pocos.Where(where).FirstOrDefault());
        }
        protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, params System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> >[] eagerLoadingProperties)
        {
            var dbSet = this._efContext.Context.Set <TAggregateRoot>();
            IEnumerable <TAggregateRoot> queryable = null;

            // dealing with eagerLoadingProperties
            if (eagerLoadingProperties != null &&
                eagerLoadingProperties.Length > 0)
            {
                var eagerLoadingPath = "";
                foreach (var eagerLoadingProperty in eagerLoadingProperties)
                {
                    eagerLoadingPath = this.GetEagerLoadingProperty(eagerLoadingProperty);
                    dbSet.Include(eagerLoadingPath);
                }
                queryable = dbSet.Where(specification.IsSatisfiedBy);
            }
            else
            {
                queryable = dbSet.Where(specification.IsSatisfiedBy);
            }
            // dealing with sorting
            if (sortPredicate != null)
            {
                switch (sortOrder)
                {
                case SortOrder.Ascending:
                    return(queryable.OrderBy(sortPredicate.Compile()).ToList());

                case SortOrder.Descending:
                    return(queryable.OrderByDescending(sortPredicate.Compile()).ToList());

                default:
                    break;
                }
            }
            // no sorting aruguments
            return(queryable.ToList());
        }
        protected override IEnumerable <TAggregateRoot> DoGetAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder)
        {
            var results = this.DoFindAll(specification, sortPredicate, sortOrder);

            if (results == null || !results.Any())
            {
                return(null);
            }
            return(results);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取where表达式
        /// </summary>
        /// <param name="s1"></param>
        /// <returns></returns>
        public static System.Linq.Expressions.Expression <Func <T, bool> > GetWhereLambda(S s1 = null, System.Linq.Expressions.Expression <Func <T, bool> > ExAdd = null)
        {
            ParameterExpression param  = Expression.Parameter(typeof(T), "c");
            Expression          Iwhere = null;

            if (ExAdd != null)
            {
                param  = ExAdd.Parameters[0];
                Iwhere = ExAdd.Body;
            }
            bool HasValue = false;

            foreach (System.Reflection.PropertyInfo pinfo in s1.GetType().GetProperties())
            {
                if (!pinfo.CanRead)
                {
                    continue;
                }
                object Selvalue = pinfo.GetValue(s1, null);
                if (Selvalue == null)
                {
                    continue;
                }
                object ob        = pinfo.GetCustomAttributes(typeof(SearchAttribute), false).FirstOrDefault();
                string TableName = null;
                string ColName   = pinfo.Name;
                Symbol symbl     = Symbol.等于;
                if (ob != null)
                {
                    SearchAttribute dA = (SearchAttribute)ob;
                    TableName = dA.TableName;
                    ColName   = dA.BaseName;
                    symbl     = dA.Symbol;
                }
                if (symbl == Symbol.无效)
                {
                    continue;
                }
                object op = pinfo.GetCustomAttributes(typeof(ExpressAttrInterface), true).FirstOrDefault();

                Expression left = null;
                if (op != null)
                {
                    left = (op as ExpressAttrInterface).GetExpression(param, typeof(T));
                }
                else
                {
                    if (string.IsNullOrEmpty(TableName))
                    {
                        left = Expression.Property(param, typeof(T).GetProperty(ColName));
                    }
                    else
                    {
                        left = Expression.Property(Expression.Property(param, typeof(T).GetProperty(TableName)), typeof(T).GetProperty(TableName).PropertyType.GetProperty(ColName));
                    }
                }
                Expression where2 = whereSymbol(symbl, left, null, Selvalue);

                if (Iwhere == null)
                {
                    Iwhere = where2;
                }
                else
                {
                    Iwhere = Expression.And(Iwhere, where2);
                }
                HasValue = true;
            }
            if (Iwhere == null || HasValue == false)
            {
                Iwhere = Expression.Constant(true);
            }
            return(Expression.Lambda <Func <T, bool> >(Iwhere, param));
        }
Exemplo n.º 9
0
 public override IEnumerable <T> FindAll <T>(System.Linq.Expressions.Expression <Func <T, bool> > criteria, int offset = 0, int limit = 0, System.Linq.Expressions.Expression <Func <T, object> > orderBy = null)
 {
     try
     {
         if (_strategy == FailoverStrategy.Failback)
         {
             Failback();
         }
         return(_current.FindAll(criteria, offset, limit, orderBy));
     }
     catch (Exception ex)
     {
         if (_logger != null)
         {
             _logger(ex);
         }
         if (_strategy == FailoverStrategy.ReplicationOnly)
         {
             throw;
         }
         Failover();
         return(_current.FindAll(criteria, offset, limit, orderBy));
     }
 }
Exemplo n.º 10
0
 public static void Update <TEntity>(this System.Data.Linq.Table <TEntity> source, System.Linq.Expressions.Expression <Func <TEntity, int, bool> > predicate, object NewValues) where TEntity : class
 {
 }
 public T Get(System.Linq.Expressions.Expression <Func <T, bool> > p)
 {
     return(_database.GetCollection <T>(typeof(T).Name).Find <T>(p).FirstOrDefault());
 }
Exemplo n.º 12
0
 public static int Delete <TEntity>(this System.Data.Linq.Table <TEntity> source, System.Linq.Expressions.Expression <Func <TEntity, int, bool> > predicate) where TEntity : class
 {
     System.Data.Linq.DataContext dc = source.Context;
     System.Data.Common.DbCommand c  = dc.GetCommand(source.Where(predicate));
     return(Delete(c));
 }
Exemplo n.º 13
0
        public IQueryable <TEntity> GetModel(Action <IRepositories.Commons.IOrderable <TEntity> > orderBy, System.Linq.Expressions.Expression <Func <TEntity, bool> > predicate)
        {
            var queryable = GetModel().Where(predicate).AsQueryable();
            var linq      = new Orderable <TEntity>(queryable);

            orderBy(linq);
            return(linq.Queryable);
        }
Exemplo n.º 14
0
 public TEntity Find(System.Linq.Expressions.Expression <Func <TEntity, bool> > predicate)
 {
     return(GetModel().FirstOrDefault(predicate));
 }
Exemplo n.º 15
0
        public virtual List <T> List(System.Linq.Expressions.Expression <Func <T, bool> > predicate)
        {
            var list = DbSet.Where(predicate).ToList();

            return(list);
        }
Exemplo n.º 16
0
 public T Find <T>(System.Linq.Expressions.Expression <Func <T, bool> > predicate) where T : class
 {
     return(GetRepository <T>().Find(predicate));
 }
        protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, int pageNumber, int pageSize)
        {
            if (pageNumber <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageNumber), pageNumber, "The pageNumber is one-based and should be larger than zero.");
            }

            if (pageSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The pageSize is one-based and should be larger than zero.");
            }

            var dbQuery = this._efContext.Context.Set <TAggregateRoot>()
                          .Where(specification.IsSatisfiedBy);
            var skip = (pageNumber - 1) * pageSize;
            var take = pageSize;

            if (sortPredicate != null)
            {
                switch (sortOrder)
                {
                case SortOrder.Ascending:
                    return(dbQuery.OrderBy(sortPredicate.Compile()).Skip(skip).Take(take).ToList());

                case SortOrder.Descending:
                    return(dbQuery.OrderByDescending(sortPredicate.Compile()).Skip(skip).Take(take).ToList());

                default:
                    break;
                }
            }
            return(dbQuery.Skip(skip).Take(take).ToList());
        }
Exemplo n.º 18
0
 public int Count <T>(System.Linq.Expressions.Expression <Func <T, bool> > predicate) where T : class
 {
     return(GetRepository <T>().Count(predicate));
 }
        protected override IEnumerable <TAggregateRoot> DoFindAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, int pageNumber, int pageSize, params System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> >[] eagerLoadingProperties)
        {
            if (pageNumber <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageNumber), pageNumber, "The pageNumber is one-based and should be larger than zero.");
            }

            if (pageSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The pageSize is one-based and should be larger than zero.");
            }

            var skip = (pageNumber - 1) * pageSize;
            var take = pageSize;

            var dbSet = this._efContext.Context.Set <TAggregateRoot>();
            IEnumerable <TAggregateRoot> queryable = null;

            // dealing with eagerLoadingProperties
            if (eagerLoadingProperties != null &&
                eagerLoadingProperties.Length > 0)
            {
                var eagerLoadingPath = "";
                foreach (var eagerLoadingProperty in eagerLoadingProperties)
                {
                    eagerLoadingPath = this.GetEagerLoadingProperty(eagerLoadingProperty);
                    dbSet.Include(eagerLoadingPath);
                }
                queryable = dbSet.Where(specification.IsSatisfiedBy);
            }
            else
            {
                queryable = dbSet.Where(specification.IsSatisfiedBy);
            }
            // dealing with sorting
            if (sortPredicate != null)
            {
                switch (sortOrder)
                {
                case SortOrder.Ascending:
                    return(queryable.OrderBy(sortPredicate.Compile()).Skip(skip).Take(take).ToList());

                case SortOrder.Descending:
                    return(queryable.OrderByDescending(sortPredicate.Compile()).Skip(skip).Take(take).ToList());

                default:
                    break;
                }
            }
            // no sorting arguments
            return(queryable.Skip(skip).Take(take).ToList());
        }
Exemplo n.º 20
0
 public System.Linq.IQueryable <T> Where <T>(System.Linq.Expressions.Expression <Func <T, bool> > predicate)
     where T : class
 {
     return(GetRepository <T>().Filter(predicate));
 }
        protected override IEnumerable <TAggregateRoot> DoGetAll(ISpecification <TAggregateRoot> specification, System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> > sortPredicate, SortOrder sortOrder, int pageNumber, int pageSize, params System.Linq.Expressions.Expression <Func <TAggregateRoot, dynamic> >[] eagerLoadingProperties)
        {
            var results = this.DoFindAll(specification, sortPredicate, sortOrder, pageNumber, pageSize, eagerLoadingProperties);

            if (results == null || !results.Any())
            {
                throw new ArgumentException("Aggregate not found.");
            }
            return(results);
        }
Exemplo n.º 22
0
 public IEnumerable <TEntity> Find(System.Linq.Expressions.Expression <Func <TEntity, bool> > predicate)
 {
     return(UOW.Context.Set <TEntity>().Where(predicate));
 }
Exemplo n.º 23
0
 public IList <SystemCountryCodePoco> GetList(System.Linq.Expressions.Expression <Func <SystemCountryCodePoco, bool> > where, params System.Linq.Expressions.Expression <Func <SystemCountryCodePoco, object> >[] navigationProperties)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
 public List <T> SearchForLocalTable <T>(System.Linq.Expressions.Expression <Func <T, bool> > predicate, int toSkip, int toTake) where T : new()
 {
     return(_liteConnection.Table <T>().Where(predicate).Skip(toSkip).Take(toTake).ToList());
 }
Exemplo n.º 25
0
 IEnumerator <TEntity> IRepository <TEntity> .Find(System.Linq.Expressions.Expression <Func <TEntity, bool> > predicate)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
 public List <T> SearchForLocalTable <T>(System.Linq.Expressions.Expression <Func <T, bool> > predicate, Dictionary <string, string> p) where T : new()
 {
     return(_liteConnection.Table <T>().Where(predicate).ToList());
     //result = await MobileService.GetTable<T>().Take(1000).Where(predicate).WithParameters(parameters).IncludeTotalCount().ToListAsync();
     //return _liteConnection.Table<T>().Where(predicate).Where(t=>t.id == ).ToList();
 }
Exemplo n.º 27
0
 public bool ExistEntityBy(System.Linq.Expressions.Expression <Func <T, bool> > predicate)
 {
     return(_idbset.Where(predicate).Any());
 }
Exemplo n.º 28
0
 public IQueryable <T> SearchForQuery <T>(System.Linq.Expressions.Expression <Func <T, bool> > predicate, Dictionary <string, string> parameters)
 {
     return(MobileService.GetTable <T>().Where(predicate).WithParameters(parameters).IncludeTotalCount().Query);
 }
Exemplo n.º 29
0
        public IQueryable <T> All(System.Linq.Expressions.Expression <Func <T, bool> > predicate)
        {
            IQueryable <T> query = _entities.Set <T>().Where(predicate);

            return(query);
        }
Exemplo n.º 30
0
 public abstract IEnumerable <T> FindBy(System.Linq.Expressions.Expression <Func <T, bool> > filter);