/// <summary> /// 添加数据 /// </summary> /// <typeparam name="TResult">返回结果数据类型</typeparam> /// <param name="model">将要添加的数据</param> /// <returns></returns> public static BsonValue Add(TDocument model) { var db = new DbCollection <TDocument>(); var id = db.Collection.Insert(model); return(id); }
/// <summary> /// 更新数据 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <typeparam name="TResult">返回结果数据类型</typeparam> /// <param name="id">数据主键</param> /// <param name="data">需要更新的数据集合</param> /// <returns></returns> public static bool Updates(List <TDocument> list) { var db = new DbCollection <TDocument>(); return(db.Collection.Update(list) > 0); }
/// <summary> /// 更新数据 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <typeparam name="TResult">返回结果数据类型</typeparam> /// <param name="id">数据主键</param> /// <param name="data">需要更新的数据集合</param> /// <returns></returns> public static bool Update(TDocument model) { var db = new DbCollection <TDocument>(); return(db.Collection.Update(model)); }
/// <summary> /// 添加数据 /// </summary> /// <typeparam name="TResult">返回结果数据类型</typeparam> /// <param name="model">将要添加的数据</param> /// <returns></returns> public static bool Adds(List <TDocument> list) { var db = new DbCollection <TDocument>(); return(db.Collection.Insert(list) > 0); }
public static LiteCollection <TDocument> GetCollection(string dbName) { var db = new DbCollection <TDocument>(dbName); return(db.Collection); }
/// <summary> /// 获取数据列表 /// </summary> /// <typeparam name="T">过滤器类型</typeparam> /// <param name="filter">过滤器</param> /// <returns></returns> public static IEnumerable <TDocument> GetList() { var db = new DbCollection <TDocument>(); return(db.Collection.FindAll()); }
/// <summary> /// 获取实体 /// </summary> /// <param name="id">数据主键</param> /// <returns></returns> public static TDocument GetModel(ObjectId id) { var db = new DbCollection <TDocument>(); return(db.Collection.FindById(id)); }
/// <summary> /// 删除数据 /// </summary> /// <typeparam name="TResult">返回结果数据类型</typeparam> /// <param name="id">数据主键</param> /// <returns></returns> public static bool Delete(ObjectId id) { var db = new DbCollection <TDocument>(); return(db.Collection.Delete(id)); }