dajpper使用教程
Posted hongmaju
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dajpper使用教程相关的知识,希望对你有一定的参考价值。
1.表结构
2、程序对应的实体类
3、基本操作
-
3.1 插入
1
2
3
4
5
6
7
8
9public int Insert(Person person, string _ConnString)
{
using (IDbConnection connection = new SqlConnection(_ConnString))
{
return connection.Execute("insert into Person(Name,Remark) values(@Name,@Remark)", person);
}
} -
3.2 删除
1
2
3
4
5
6
7public int Delete(Person person, string connectionString)
{
using (IDbConnection connection = new SqlConnection(connectionString))
{
return connection.Execute("delete from Person where [email protected]", person);
}
} -
3.3 修改
1
2
3
4
5
6
7public int Update(Person person, string connectionString)
{
using (IDbConnection connection = new SqlConnection(connectionString))
{
return connection.Execute("update Person set [email protected] where [email protected]", person);
}
} -
3.4 查询
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/// <summary>
/// 批量修改
/// </summary>
/// <param name="persons"></param>
/// <param name="connectionString"></param>
/// <returns></returns>
public int Update(List<Person> persons, string connectionString)
{
using (IDbConnection connection = new SqlConnection(connectionString))
{
return connection.Execute("update Person set [email protected] where [email protected]", persons);
}
}
/// <summary>
/// 无参查询所有数据
/// </summary>
/// <returns></returns>
public List<Person> Query(string connectionString)
{
using (IDbConnection connection = new SqlConnection(connectionString))
{
return connection.Query<Person>("select * from Person").ToList();
}
} - 其余内容:https://hongmaju.github.io/2018/06/19/Dapper%E7%9A%84%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/#more
以上是关于dajpper使用教程的主要内容,如果未能解决你的问题,请参考以下文章