码迷,mamicode.com
首页 > 移动开发 > 详细

dapper的使用

时间:2020-07-10 00:09:48      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:from   open   code   interface   aot   else   div   close   inter   

 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的使用

标签:from   open   code   interface   aot   else   div   close   inter   

原文地址:https://www.cnblogs.com/ntg2/p/13276971.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!