我在通过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。