Dapper的简单使用(初学者归纳)

天下之事常成于困约,而败于奢靡。这篇文章主要讲述Dapper的简单使用(初学者归纳)相关的知识,希望能为你提供帮助。
Dapper的简单使用(初学者归纳)//引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Model;
using Dapper;

//建立数据库连接
public static SqlConnection sqlconn()
{
string ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
var conntion = new SqlConnection(ConnString);
conntion.Open();
return conntion;
}
//列表
public List< User> GetList()
{
using (IDbConnection con = UserDal.sqlconn())
{
string sqlcommandtex = "select * from tb_User";
List< User> userlist = SqlMapper.Query< User> (con, sqlcommandtex).ToList();
return userlist;
}
}
【Dapper的简单使用(初学者归纳)】//删除
public int del(int id)
{
using (IDbConnection con = UserDal.sqlconn())
{
string comm = "delete from tb_User where id = @id";

int res = con.Execute(comm, new { id = id });
return res;
}
}
//参数列表
public User GetUser(int id)
{
using(IDbConnection con = UserDal.sqlconn())
{
string sql = "select * from tb_User where [email  protected]";
User q = con.Query< User> (sql, new { id = id }).SingleOrDefault();
return q;
}
}
//修改
public int Upd(User qq)
{
using(IDbConnection con = UserDal.sqlconn())
{
string sql = "update tb_User set [email  protected],[email  protected],[email  protected] where [email  protected]";
int q = con.Execute(sql, qq);
return q;
}
}
























































    推荐阅读