Exemplo n.º 1
0
 /// <summary>
 /// 向数据库中插入 User 实体
 /// </summary>
 /// <param name="entity">UserModel对象</param>
 /// <returns>自增主键</returns>
 public long InsertUser(UserEntity entity)
 {
     var parameters = new StatementParameterCollection();
     parameters.AddOutParameter("@UserId", DbType.Int64, 8);
     parameters.AddInParameter("@UserName", DbType.String, entity.UserName);
     parameters.AddInParameter("@CreateTime", DbType.DateTime, entity.CreateTime);
     parameters.AddInParameter("@UpdateTime", DbType.DateTime, entity.UpdateTime);
     
     try
     {
         DB.ExecSp("spA_User_i", parameters);
         return Convert.ToInt64(parameters["@UserId"].Value);
     }
     catch (Exception ex)
     {
         throw new DalException("调用 UserDal 时,访问 InsertUser 时出错", ex);
     }
 }