首页 > 其他 > 详细

dajpper使用教程

时间:2018-06-21 22:00:30      阅读:229      评论:0      收藏:0      [点我收藏+]

1.表结构

技术分享图片
技术分享图片

2、程序对应的实体类

技术分享图片
技术分享图片

3、基本操作

  • 3.1 插入

    1
    2
    3
    4
    5
    6
    7
    8
    9
    public 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
    7
    public int Delete(Person person, string connectionString)
    {
    using (IDbConnection connection = new SqlConnection(connectionString))
    {
    return connection.Execute("delete from Person where id=@ID", person);
    }
    }
  • 3.3 修改

    1
    2
    3
    4
    5
    6
    7
    public int Update(Person person, string connectionString)
    {
    using (IDbConnection connection = new SqlConnection(connectionString))
    {
    return connection.Execute("update Person set name=@Name where id=@ID", 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 name=@name where id=@ID", 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使用教程

原文:https://www.cnblogs.com/hongmaju/p/9210937.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!