如何通过Dapper在ExecuteScalarSQL中返回对象

时间:2017-08-19 07:11:29

标签: c# dapper

我在通过Dapper Framework进行插入(实体)时遇到困难。

  var insertproduct = SqlHelper.ExecuteScalarSQL<Product>("insert into Product(Name) values(@Name)", new { Name = product.Name });

辅助功能:

 public static T ExecuteScalarSQL<T>(string sql, dynamic param = null, dynamic outParam = null, SqlTransaction transaction = null, int? commandTimeout = null, string connectionString = null)
        {
            CombineParameters(ref param, outParam);

            using (SqlConnection connection = new SqlConnection(GetConnectionString(connectionString)))
            {
                connection.Open();
                return connection.ExecuteScalar<T>(sql, param: (object)param, transaction: transaction, commandTimeout: GetTimeout(commandTimeout), commandType: CommandType.Text);
            }
        }

正在成功插入,但它将插入的对象返回为null。

0 个答案:

没有答案