• ABP入门教程(六)ABP支持DataTable


    首先要添加一个辅助类MsSqlHelper 百度一下就有, 在 .netCore3.1以上需要用Microsoft.Data.SqlClient替代Systemt.Data.SqlClient
    然后在RepositoryBase里面添加常用的查询方法, 如下

    using Abp.Domain.Entities;
    using Abp.Domain.Repositories;
    using Abp.EntityFrameworkCore;
    using Abp.EntityFrameworkCore.Repositories;
    using Microsoft.Data.SqlClient;
    using System.Data;
    
    namespace Xxxxx.EntityFrameworkCore.Repositories
    {
        /// 
        /// Base class for custom repositories of the application.
        /// 
        /// Entity type
        /// Primary key type of the entity
        public abstract class XxxxxRepositoryBase : EfCoreRepositoryBase
            where TEntity : class, IEntity
        {
            protected XxxxxRepositoryBase(IDbContextProvider dbContextProvider)
                : base(dbContextProvider)
            {
            }
    
            // Add your common methods for all repositories
    
            // Add your common methods for all repositories
            public int ExecuteNonQuery(string sql)
            {
                return MsSqlHelper.ExecuteNonQuery(GetTransaction() as SqlTransaction, CommandType.Text, sql);
            }
    
            public string ExecuteQueryString(string sql)
            {
                return (string)MsSqlHelper.ExecuteScalar(GetTransaction() as SqlTransaction, CommandType.Text, sql);
            }
    
            public DataTable ExecuteQuery(string sql)
            {
                var ds = ExecuteQueryDataSet(sql);
                if (null == ds)
                {
                    return null;
                }
    
                return ds.Tables[0];
            }
    
            public DataTable ExecuteQuery(string sql, IDbDataParameter[] dbParameters)
            {
                DataSet ds = MsSqlHelper.ExecuteDataset(GetTransaction() as SqlTransaction, sql, dbParameters);
                if (null != ds && ds.Tables.Count > 0)
                {
                    return ds.Tables[0];
                }
                else
                {
                    return null;
                }
            }
    
            public DataSet ExecuteQueryDataSet(string sql)
            {
                return MsSqlHelper.ExecuteDataset(GetTransaction() as SqlTransaction, CommandType.Text, sql);
            }
    
            public DataTable RunProcTable(string procName, params SqlParameter[] dbParameters)
            {
                DataSet ds = RunProc(procName, dbParameters);
                if (null != ds && ds.Tables.Count > 0)
                {
                    return ds.Tables[0];
                }
                else
                {
                    return null;
                }
            }
    
            public DataSet RunProc(string procName, SqlParameter[] dbParameters)
            {
                var ds = MsSqlHelper.ExecuteDataset(GetTransaction() as SqlTransaction, CommandType.StoredProcedure, procName, dbParameters);
                return ds;
            }
    
            public int RunProc(string procName)
            {
                return MsSqlHelper.ExecuteNonQuery(GetTransaction() as SqlTransaction, CommandType.StoredProcedure, procName);
            }
        }
    
        /// 
        /// Base class for custom repositories of the application.
        /// This is a shortcut of  for  primary key.
        /// 
        /// Entity type
        public abstract class XxxxxRepositoryBase : XxxxxRepositoryBase, IRepository
            where TEntity : class, IEntity
        {
            protected XxxxxRepositoryBase(IDbContextProvider dbContextProvider)
                : base(dbContextProvider)
            {
            }
    
            // Do not add any method here, add to the class above (since this inherits it)!!!
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
  • 相关阅读:
    asp.net core之路由
    腾讯云轻量4核8G12M带宽服务器租用价格和S5实例报价
    IOU 与 IOF
    数据结构学习笔记(第八章 排序-内部排序)
    k8s 中 Pod 的控制器
    Linux 命令(212)—— ssh-add 命令
    抓包整理————静态路由[十六]
    02 MIT线性代数-矩阵消元 Elimination with matrices
    Java 是什么?Java 的特性、编程环境
    精灵图和 base64 之间如何选择?
  • 原文地址:https://blog.csdn.net/zheyiw/article/details/126389547