Dapper.net 输出存储过程实例

1、存储过程名:

 public static class CampaignTrackingDomainSql
    {
        /// <summary>
        /// proc
        /// </summary>
        public static readonly string PageProcSql = @"NewsLetterSystem_TrackingDB_GetClicksDomainV2";
    }

2、DapperUtil

  /// <summary>
        ///  get datatable by query proc
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parms"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static DataTable QueryDataTableByStoredProc(string sql, dynamic parms, string connectionString = null)
        {
            DataTable dataTable = new DataTable();
            using (IDbConnection connection = OpenConnection(connectionString))
            {
                return QueryDataTableByStoredProc(connection, sql, parms, connectionString);
            }
        }

3、DapperService:

  /// <summary>
        /// get datatable
        /// </summary>
        /// <param name="parModel"></param>
        /// <returns></returns>
        public DataTable GetDataTable(int campId)
        {
            DynamicParameters par = new DynamicParameters();

            par.Add("@CampaignID", campId);
            par.Add("@PageStart", 1);
            par.Add("@PageEnd", 1);
            par.Add("@IsPage", false);
            par.Add("@Total", 0, DbType.Int32, ParameterDirection.Output);
            par.Add("@TotalClick", 0, DbType.Int32, ParameterDirection.Output);
            par.Add("@TotalUniqueClick", 0, DbType.Int32, ParameterDirection.Output);

            DataTable dt = SqlMapperUtil.QueryDataTableByStoredProc(CampaignTrackingDomainSql.PageProcSql, par);
            int total = par.Get<int>("@Total");
            int totalOpen = par.Get<int>("@TotalClick");
            int totalUniqueOpen = par.Get<int>("@TotalUniqueClick");
            return dt;
        }

 

posted @ 2017-04-26 10:10  大空白纸  阅读(2381)  评论(0编辑  收藏  举报