1.使用非自增列或者GUID列的主键时,需调用Insert--只要是非数字主键建议使用如下扩展方法
{ TKey newId; using (IDbConnection conn = SessionFactory.CreateConnection(ConnectionStr)) { newId = conn.Insert<TKey, T>(entity);//就是一个重载方法,默认的只能返回数字或者null } return newId; }
2.
- 当列名与实体类的属性名不一致时使用[Column(“ColumnName”)]Attrubute
- 使用[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(); }