public string GetProcess <T>(string Table, T ObjType, dynamic query) { var TableInstance = Program.db.GetCollection <T>(Table); List <T> tmp; try { LiteDB.Query q = LiteDB.Query.All(); Type tt = typeof(T); PropertyInfo[] props = tt.GetProperties(); foreach (string item in query) { Type TypeOfProperty = props.FirstOrDefault(w => w.Name == item).PropertyType; string newItem = item; if (item == "Id") { newItem = "_id"; } q = LiteDB.Query.And(q, LiteDB.Query.EQ(newItem, Convert.ChangeType(query[item].Value, TypeOfProperty))); } tmp = TableInstance.Find(q).ToList(); } catch (Exception ex) { return(ex.Message); } return(JsonConvert.SerializeObject(tmp)); }
public static List <BsonDocument> Find(this LiteEngine engine, string collection, BsonExpression where) { var q = new LiteDB.Query(); if (where != null) { q.Where.Add(where); } var docs = new List <BsonDocument>(); using (var r = engine.Query(collection, q)) { while (r.Read()) { docs.Add(r.Current.AsDocument); } } return(docs); }
public bool CheckExists <T>(LiteDB.Query query, ICollection collection) where T : new() { return(Database.GetCollection <T>(collection.Name).Exists(query)); }