dapper的使用

万事须己运,他得非我贤。这篇文章主要讲述dapper的使用相关的知识,希望能为你提供帮助。

public abstract class AsbCommection { private static string con = System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString; public static IDbConnection GetConnection() { IDbConnection conn = new SqlConnection(con); if (conn.State == ConnectionState.Closed) { conn.Open(); } return conn; } }

public interface IDAL { List< Tresult> Show< Tresult> (string sql) where Tresult : class, new(); int Insert(string sql); int Del(string sql); } public class SqlDBHelper : IDAL { private IDbConnection conn = AsbCommection.GetConnection(); public int Del(string sql) { return conn.Execute(sql); }public int Insert(string sql) { return conn.Execute(sql); }public List< Tresult> Show< Tresult> (string sql) where Tresult : class, new() { return conn.Query< Tresult> (sql).ToList(); } }

public class RoweBLL { SqlDBHelper db = new SqlDBHelper(); public List< RoweModel> ShowRowe(string YName) { if (YName ==null||YName=="") { string sql = "select * from YueKao0707TB s join YuekaoType e on s.TId=e.TId"; return db.Show< RoweModel> (sql); } else { string sql = $"select * from YueKao0707TB s join YuekaoType e on s.TId=e.TId where YName like ‘{"%" + YName + "%"}‘"; return db.Show< RoweModel> (sql); }} public int InsertRowe(RoweModel m) { string sql = $"insert into YueKao0707TB values(‘{m.YName}‘,‘{m.TId}‘,‘{m.ZPrco}‘,‘{m.SPrco}‘,‘{m.ZNum}‘,‘{m.SNum}‘,‘{m.HStrac}‘)"; return db.Insert(sql); } public List< RoweTypeModel> ShowType() { string sql = "select * from YuekaoType"; return db.Show< RoweTypeModel> (sql); } public int DelRowe(int Id) { string sql = "delete from YueKao0707TB where Id=" + Id; return db.Del(sql); } }

【dapper的使用】 

    推荐阅读