码迷,mamicode.com
首页 > 其他好文 > 详细

dajpper使用教程

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

标签:line   基本   实体   fancybox   src   from   content   修改   let   

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使用教程

标签:line   基本   实体   fancybox   src   from   content   修改   let   

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

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