我有一些代码(使用dapper)正在对我的数据库执行查询(ASE 12)。 sql具有这样的where子句 where r.reg_id = @reg_id
现在数据库中的reg_id列是一种数字类型,长度为6,Prec 18,小数位数为0
在代码中,@reg_id变量是一个Int32,我希望在调用 async方法查询时发生异常,但是它永远不会出错...
问题:是否需要在dapper中进行设置/配置以获取数据类型错误以排除异常?
下面的代码将起作用,因为我将数据类型设置为十进制,但是对于其他团队成员,我希望踢出一个例外,以便他们知道问题出在哪里...有什么想法?
public async Task<IEnumerable<CentersForRegIdResponse>> Handle(CentersForRegIdQuery request, CancellationToken cancellationToken)
{
StringBuilder sql = new StringBuilder();
sql.Append(" SELECT c.ctr_id, RTRIM(LTRIM(c.ctr_shname)) AS ctr_shname, RTRIM(LTRIM(r.reg_name)) AS reg_name ");
sql.Append(" FROM center c, ");
sql.Append(" region r ");
sql.Append(" WHERE c.jcc_active = 'Y' and c.reg_id = r.reg_id and r.reg_id = @reg_id ");
sql.Append(" ORDER BY c.ctr_shname ");
string query = sql.ToString();
// custom mapping
_dapperTools.DapperCustomMapping<CentersForRegIdResponse>();
try
{
using (IDbConnection dbConnection = _dapperTools._aseconnection)
{
// example get list of rows by args
var arguments = new
{
@reg_id = request.RegId
};
IEnumerable<CentersForRegIdResponse> allRows =
await dbConnection.QueryAsync<CentersForRegIdResponse>(query, arguments);
return allRows;
}
}
catch (Exception ex)
{
_dapperTools.ReportSqlError(_log, query, ex);
return null;
}
}
public class CentersForRegIdQuery : IRequest<IEnumerable<CentersForRegIdResponse>>
{
public Decimal RegId { get; set; }
}