使用Dapper.SimpleCURD注意事项

  1. 使用非自增列或者GUID列的主键时,需调用Insert
{
            TKey newId;
            using (IDbConnection conn = SessionFactory.CreateConnection(ConnectionStr))
            {
                newId = conn.Insert(entity);
            }

            return newId;
}
  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(sql).ToList();
}
  1. 使用SimpleCURD的GetList方法使用字符串条件时,where条件应和表的列名一致
 using (IDbConnection conn = SessionFactory.CreateConnection(ConnectionStr))
            {
                string condition = "WHERE sModelName = @ModelName OR sModelDesc = @ModelDesc";
                return conn.GetList(condition, new { ModelName = modelName, ModelDesc = modelDesc}).ToList();
            }

你可能感兴趣的:(C#,Dapper)