Ejemplo n.º 1
0
 public IQueryable <E> GetByMaxCreateTime(IQueryable <E> list, DateTime create_at_max)
 {
     if (typeof(IGetting).IsAssignableFrom(typeof(E)))
     {
         Expression <Func <E, bool> > node = (E q) => ((IGetting)q).CreateTime <= create_at_max;
         node = (Expression <Func <E, bool> >)RemoveCastsVisitor.Visit(node);
         return(Queryable.Where <E>(list, node));
     }
     return(list);
 }
Ejemplo n.º 2
0
 public IQueryable <E> GetSinceId(int sinceId, IQueryable <E> list)
 {
     if (typeof(IGetting).IsAssignableFrom(typeof(E)))
     {
         Expression <Func <E, bool> > node = (E q) => ((IGetting)q).Id >= sinceId;
         node = (Expression <Func <E, bool> >)RemoveCastsVisitor.Visit(node);
         return(Queryable.Where <E>(list, node));
     }
     return(list);
 }
Ejemplo n.º 3
0
 public virtual IQueryable <T> GetActive(Expression <Func <T, bool> > predicate)
 {
     if (typeof(IActivable).IsAssignableFrom(typeof(T)))
     {
         var sourceQuerable = _dbSet.Where <T>(predicate);
         Expression <Func <T, bool> > checkActiveExpress = (T t) => ((IActivable)t).Active;
         var cleanCheckActiveExpress = (Expression <Func <T, bool> >)RemoveCastsVisitor.Visit(checkActiveExpress);
         return(sourceQuerable.Where(cleanCheckActiveExpress));
     }
     return(this.Get(predicate));
 }
Ejemplo n.º 4
0
 public virtual Task <T> FirstOrDefaultActiveAsync(Expression <Func <T, bool> > predicate)
 {
     if (typeof(IActivable).IsAssignableFrom(typeof(T)))
     {
         var sourceQuerable = _dbSet.Where <T>(predicate);
         Expression <Func <T, bool> > checkActiveExpress = (T t) => ((IActivable)t).Active;
         var cleanCheckActiveExpress = (Expression <Func <T, bool> >)RemoveCastsVisitor.Visit(checkActiveExpress);
         return(sourceQuerable.FirstOrDefaultAsync(cleanCheckActiveExpress));
     }
     return(this.FirstOrDefaultAsync(predicate));
 }
Ejemplo n.º 5
0
        //  public JsonSerializerSettings ToJson(string fields)
        //{
        //    var jsonResolver = new PropertyRenameAndIgnoreSerializerContractResolver();
        //    var jsonProperty = _model.GetType().GetProperties()
        //         .SelectMany(p => p.GetCustomAttributes(typeof(JsonPropertyAttribute))
        //                           .Cast<JsonPropertyAttribute>())
        //         .Select(jp => jp.PropertyName);
        //    if (!string.IsNullOrEmpty(fields))
        //    {
        //        foreach (var item in jsonProperty)
        //        {
        //            if (!fields.Contains(item))
        //            {
        //                jsonResolver.IgnoreProperty(typeof(AgencyServiceModel), item);
        //            }
        //        }
        //    }
        //    var serializerSettings = new JsonSerializerSettings
        //    {
        //        ContractResolver = jsonResolver
        //    };
        //    return serializerSettings;
        //}

        public IQueryable <E> GetByIds(List <int> ids, IQueryable <E> list)
        {
            if (typeof(IGetting).IsAssignableFrom(typeof(E)))
            {
                Expression <Func <E, bool> > node = (E q) => ids.Contains(((IGetting)q).Id);
                node = (Expression <Func <E, bool> >)RemoveCastsVisitor.Visit(node);

                return(Queryable.Where <E>(list, node));
            }
            return(list);
        }
Ejemplo n.º 6
0
 public virtual TEntity FirstOrDefaultActive()
 {
     if (this.IsEntityActivable)
     {
         Expression <Func <TEntity, bool> > getActive = q => ((IActivable)q).Active;
         getActive = (Expression <Func <TEntity, bool> >)RemoveCastsVisitor.Visit(getActive);
         return(this.dbSet.FirstOrDefault(getActive));
     }
     else
     {
         return(this.FirstOrDefault());
     }
 }
Ejemplo n.º 7
0
 public virtual IQueryable <TEntity> GetActive()
 {
     if (typeof(IActivable).IsAssignableFrom(typeof(TEntity)))
     {
         Expression <Func <TEntity, bool> > getActive = q => ((IActivable)q).Active;
         getActive = (Expression <Func <TEntity, bool> >)RemoveCastsVisitor.Visit(getActive);
         return(this.Get().Where(getActive));
     }
     else
     {
         return(this.Get());
     }
 }
Ejemplo n.º 8
0
 public Task <TEntity> FirstOrDefaultActiveAsync(Expression <Func <TEntity, bool> > predicate)
 {
     if (typeof(IActivable).IsAssignableFrom(typeof(TEntity)))
     {
         Expression <Func <TEntity, bool> > getActive = q => ((IActivable)q).Active;
         getActive = (Expression <Func <TEntity, bool> >)RemoveCastsVisitor.Visit(getActive);
         return(this.dbSet.Where(predicate).FirstOrDefaultAsync(getActive));
     }
     else
     {
         return(this.FirstOrDefaultAsync(predicate));
     }
 }