internal LiteCollection(string name, DbEngine engine, BsonMapper mapper, Logger log) { _name = name; _engine = engine; _mapper = mapper; _log = log; _visitor = new QueryVisitor <T>(mapper); _includes = new List <Action <BsonDocument> >(); }
public LiteCollection(string name, LazyLoad <LiteEngine> engine, BsonMapper mapper, LoggerWrap log) { _name = name ?? mapper.ResolveCollectionName(typeof(T)); _engine = engine; _mapper = mapper; _log = log; _visitor = new QueryVisitor <T>(mapper); _includes = new List <Action <BsonDocument> >(); }
/// <summary> /// Find the first document using Linq expression. Returns null if not found. Must have indexes on predicate. /// </summary> public T FindOne(Expression <Func <T, bool> > predicate) { return(this.Find(QueryVisitor.Visit(predicate)).FirstOrDefault()); }
/// <summary> /// Returns true if query returns any document. This method does not deserialize any document. Needs indexes on query expression /// </summary> public bool Exists(Expression <Func <T, bool> > predicate) { return(this.Exists(QueryVisitor.Visit(predicate))); }
/// <summary> /// Count documnets with a query. This method does not deserialize any document. Needs indexes on query expression /// </summary> public int Count(Expression <Func <T, bool> > predicate) { return(this.Count(QueryVisitor.Visit(predicate))); }
/// <summary> /// Find documents inside a collection using Linq expression. Must have indexes in linq expression /// </summary> public IEnumerable <T> Find(Expression <Func <T, bool> > predicate) { return(this.Find(QueryVisitor.Visit(predicate))); }
/// <summary> /// Create a new permanent index in all documents inside this collections if index not exists already. /// </summary> /// <param name="property">Property linq expression</param> /// <param name="unique">Create a unique values index?</param> public virtual bool EnsureIndex <K>(Expression <Func <T, K> > property, bool unique = false) { var p = QueryVisitor.GetProperty <T, K>(property); return(this.EnsureIndex(p.Name, unique)); }
/// <summary> /// Delete document based on a LINQ query. /// </summary> public virtual int Delete(Expression <Func <T, bool> > predicate) { return(this.Delete(QueryVisitor.Visit(predicate))); }