コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
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));
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        public static LiteCollection <TDocument> GetCollection(string dbName)
        {
            var db = new DbCollection <TDocument>(dbName);

            return(db.Collection);
        }
コード例 #6
0
        /// <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());
        }
コード例 #7
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">数据主键</param>
        /// <returns></returns>
        public static TDocument GetModel(ObjectId id)
        {
            var db = new DbCollection <TDocument>();

            return(db.Collection.FindById(id));
        }
コード例 #8
0
        /// <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));
        }