using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using Dapper; namespace DAL { public class DapperHelper : Absconnection, IDal { IDbConnection conn = Absconnection.dbConnection(); /// <summary> /// 增删改 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <returns></returns> public int Excout<T>(string sql) where T : class, new() { return conn.Execute(sql); } /// <summary> /// 查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sql"></param> /// <returns></returns> public List<T> Query<T>(string sql) where T : class, new() { return conn.Query<T>(sql).ToList(); } } }
连接两个接口Absconnection和IDal
Absconnection是连接字符串
IDal是接口泛型方法,用于调用