定义IMongoRepositoryBase接口

public interface IMongoRepositoryBase
    {
        /// <summary>
        /// 新增一条数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        void Insert<T>(T model) where T : class;
        /// <summary>
        /// 批量新增数据
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="list">泛型集合</param>
        void Insert<T>(IList<T> list) where T : class;

/// <summary>
        /// 更新一条数据
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="model">实体类</param>
        /// <param name="where">查询条件</param>
        bool Update<T>(T model, Expression<Func<T, bool>> where) where T : class;

/// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where"></param>
        bool Delete<T>(Expression<Func<T, bool>> where) where T : class;

/// <summary>
        /// 根据条件,获取一条记录
        /// </summary>
        /// <typeparam name="T">返回值类型</typeparam>
        /// <param name="where"></param>
        /// <returns></returns>
        T GetModel<T>(Expression<Func<T, bool>> where) where T : class;

/// <summary>
        /// 获取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where"></param>
        /// <returns></returns>
        IList<T> GetList<T>(Expression<Func<T, bool>> where) where T : class;

/// <summary>
        /// 获取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        IList<T> GetList<T>(Expression<Func<T, object>> orderBy) where T : class;
        /// <summary>
        /// 获取带排序的列表
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="where">查询条件</param>
        /// <param name="orderBy">排序</param>
        /// <returns></returns>
        IList<T> GetList<T>(Expression<Func<T, bool>> where, Expression<Func<T, object>> orderBy) where T : class;

/// <summary>
        /// 获取分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="where"></param>
        /// <param name="orderby"></param>
        /// <returns></returns>
        IList<T> GetList<T>(int pageIndex, int pageSize, Expression<Func<T, bool>> where, Expression<Func<T, object>> orderby) where T : class;

/// <summary>
        /// 获取总记录数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where"></param>
        /// <returns></returns>
        long GetTotalCount<T>(Expression<Func<T, bool>> where) where T : class;

}

定义MongoRepositoryBase类,并实现IMongoRepositoryBase接口

  ?  ? ) * pageSize;

return collection.Find(where).SortByDescending(orderby).Skip(skip).Limit(pageSize).ToListAsync().Result;
        }

/// <summary>
        /// 获取总记录数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where"></param>
        /// <returns></returns>
        public long GetTotalCount<T>(Expression<Func<T, bool>> where) where T : class
        {
            //获取链表
            var collection = db.GetCollection<T>(collectionName);

if (where != null)
            {
                return collection.CountAsync(where).Result;
            }
            else
            {
                return collection.CountAsync(new BsonDocument()).Result;
            }
        }
    }

MongoDB官网驱动仓库封装的更多相关文章

  1. Mongodb 官网驱动2.2.4.26版本 增,删 改,查

    Mongodb是3.2.7版本 最近在学习mongodb数据库在网上找到的都不是2.X版本以下的,因为驱动从2.X以后修改了很多,以前不支持linq现2.X也支持了, Mongodb 启动服务就不说了 ...

  2. Mongodb 官网驱动2.2.4.26版本 增,删 改,查,mongodb2.2.4.26

    Mongodb是3.2.7版本 最近在学习mongodb数据库在网上找到的都不是2.X版本以下的,因为驱动从2.X以后修改了很多,以前不支持linq现2.X也支持了, Mongodb 启动服务就不说了 ...

  3. Ubuntu14.04下Mongodb官网卸载部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 前期博客 Ubuntu14.04下Mongodb官网安装部署步骤(图文详解)(博主推荐) https://docs.mongodb.com/manual/tutorial/ins ...

  4. Ubuntu16.04下Mongodb官网卸载部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 前期博客 Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐) https://docs.mongodb.com/manual/tutorial/ins ...

  5. MongoDB 红宝书-MongoDB官网使用指南

    本文转载自Mongodb中文社区:http://www.mongoing.com/archives/27359 无论你是MongoDB的使用者.爱好者.初学者还是路人甲,有一个学习与进修的资源宝藏是千 ...

  6. MongoDB 官网教程 下载 安装

    官网:https://www.mongodb.com/ Doc:https://docs.mongodb.com/ Manual:https://docs.mongodb.com/manual/ 安装 ...

  7. Ubuntu14.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 在这篇博客里,我采用了非官网的安装步骤,来进行安装.走了弯路,同时,也是不建议.因为在大数据领域和实际生产里,还是要走正规的为好. Ubuntu14.04下Mongodb(离线安 ...

  8. Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 在这篇博客里,我采用了非官网的安装步骤,来进行安装.走了弯路,同时,也是不建议.因为在大数据领域和实际生产里,还是要走正规的为好. Ubuntu16.04下Mongodb(离线安 ...

  9. Linux小项目/rhel-基于同步官网yum仓库数据搭建本地yum服务器

    本文的实验环境:aws上的Redhat 7.x , 同样也适用于Centos 7.x 简单说主要分为三步: (1) 向官网同步yum数据,可以根据具体情况,创建脚本及配置周期例行任务  (2) 搭建w ...

随机推荐

  1. ServletContext获取的方法

    ServletContext  代表当前web应用 如何获取ServletContext对象 ServletConfig对象中维护了ServletContext对象的引用,可以通过以下方式获得 Ser ...

  2. Excel导入-----导出(包含所选和全部)操作

    在做系统的时候,很多时候信息量太大,这时候就需要进行Excel表格信息的导入和导出,今天就来给大家说一下我使用Excel表格信息导入和导出的心得. 1:首先需要在前端显示界面View视图中添加导入Ex ...

  3. IE9下WebUploader上传图片跨域问题

    作为前端,这一次踩到后台xml配置的坑. IE9下上传图片通过flash插件,一直发送http://192.168.0.8:8888/crossdomain.xml请求,状态码为404,原因是上传图片 ...

  4. python第二天基础1-1

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'wupeiqi' print name 二.三元运算 result = 值1  ...

  5. lua 快速排序

    function partion(arr, left, right) local tmp = arr[left] while left < right do while left < ri ...

  6. ubuntu 14 中tomcat的开机启动设置

    开机自启动,将要执行的语句写入/etc/rc.local. #!/bin/sh -e # # rc.local # # This script is executed at the end of ea ...

  7. step by step 之餐饮管理系统七(点菜模块实现)

    好长时间没有更新这个系列了,一是因为这段时间比较忙,有很多事情,二来要学习新的东西,AngularJs,devExpress这两上框架,都是比较有名的框架,先上图: 上面就是用来点菜的界面,左边是已点 ...

  8. 【Visual Lisp】图元选择集专题

    图元选择集专题;;★★★01.选择集操作★★★(setq ss (ssadd));;创建一个空选择集(ssadd (car(entsel)) ss);;将点取的图元添加到ss选择集中,可以不用setq ...

  9. Global文件编译发布,代码不执行的问题与解决

    问题:在Application_BeginRequest添加防止跨站点注入的过滤代码,VS2005编译成DLL发布后发现代码不会被执行: 环境:windows server 2008 r2 x64位  ...

  10. SQL导入Excel文件

    如果表已存在,SQL语句为: insert into aa select * from OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source=D ...