zoukankan      html  css  js  c++  java
  • 使用Dapper.SimpleCURD注意事项

    1.使用非自增列或者GUID列的主键时,需调用Insert--只要是非数字主键建议使用如下扩展方法

    {
                TKey newId;
                using (IDbConnection conn = SessionFactory.CreateConnection(ConnectionStr))
                {
                    newId = conn.Insert<TKey, T>(entity);//就是一个重载方法,默认的只能返回数字或者null
                }
    
                return newId;
    }

    2.

    1. 当列名与实体类的属性名不一致时使用[Column(“ColumnName”)]Attrubute
    2. 使用[Column]标签时 如果使用Dapper.Query方法 在sql语句中select出的列需要使用as创建列别名
    using (IDbConnection conn = SessionFactory.CreateConnection(ConnectionStr))
    {
                    string sql = "SELECT sAreaID AS AreaID, sAreaCode AS AreaCode,sSite AS Site,sAreaDesc AS AreaDesc,sCreationBy AS CreationBy,tCreationDate AS CreationDate,sLastupdateBy AS LastupdateBy,tLastupdateDate AS LastupdateDate FROM Eqp_Area";
                    return conn.Query<EqpArea>(sql).ToList();
    }

    3.使用SimpleCURD的GetList方法使用字符串条件时,where条件应和表的列名一致

     using (IDbConnection conn = SessionFactory.CreateConnection(ConnectionStr))
                {
                    string condition = "WHERE sModelName = @ModelName OR sModelDesc = @ModelDesc";
                    return conn.GetList<EqpModel>(condition, new { ModelName = modelName, ModelDesc = modelDesc}).ToList();
                }
  • 相关阅读:
    快速切题 sgu102.Coprimes 欧拉函数 模板程度 难度:0
    快速切题 sgu104. Little shop of flowers DP 难度:0
    poj 1163 The Triangle 搜索 难度:0
    sgu101 欧拉路径 难度:1
    快速切题 poj3414 Pots
    xml学习
    linux
    常用排序算法
    C++面试题目
    软件工程的一些问题
  • 原文地址:https://www.cnblogs.com/djd66/p/14808265.html
Copyright © 2011-2022 走看看