public LiteDbQuery(LiteQueryable <T> query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } _query = query; }
public T GetOrCreateIdModel <T>(LiteQueryable <T> col, ObjectId id, Action <T> save) where T : ModelBase, new() { lock (DataLock) { var d = col.FirstOrDefault(x => x.Id == id); if (d != null) { return(d); } d = new T { Id = id }; save.Invoke(d); return(d); } }
private IEnumerable <TEntity> GetAllCached(OptionsFilter options) { LiteQueryable <TEntity> queryDB = DbContext.Repository.Query <TEntity>(); if (options.id_like != null) { foreach (var item in options.id_like) { queryDB = queryDB.Where(x => options.id_like.Contains(x.Id)); } } if (options._filter != null && options._filter.Count > 0) { var listPredicate = Filter.ByQueryParams <TEntity>(options); foreach (var predicate in listPredicate) { queryDB = queryDB.Where(predicate); } } if (options._take != 0) { queryDB = queryDB.Limit(options._take); } if (options._skip != 0) { queryDB = queryDB.Skip(options._skip); } if (options._page != 0) { var take = options._take == 0 ? 10 : options._take; var page = (options._page - 1) * take; queryDB = queryDB.Skip(page).Limit(take); } if (options._sort != null) { return(Filter.Sort(options, queryDB.ToList())); } return(queryDB.ToEnumerable()); }
public IQuery <T> Where(Expression <Func <T, bool> > predicate) { _query = _query.Where(predicate); return(this); }
public IQuery <T> Skip(int skip) { _query = _query.Skip(skip); return(this); }
public IQuery <T> Limit(int limit) { _query = _query.Limit(limit); return(this); }
public IQuery <T> Include <TK>(Expression <Func <T, TK> > dbref) { _query = _query.Include(dbref); return(this); }
public static T FirstOrDefault <T>(this LiteQueryable <T> query, Expression <Func <T, bool> > predicate) { return(query.Where(predicate).FirstOrDefault()); }