[Dapper+Oracle.ManagedDataAccess] Value does not fall within the expected range.

  • 598
  • 0

今天使用 Dapper 查詢 SQL時,出現 於 System.ArgumentException 擲回例外狀況: 'Oracle.ManagedDataAccess.dll' Value does not fall within the expected range.

 查看 StackTrace 看到在建立 OracleParameter 時發生錯誤

   at Oracle.ManagedDataAccess.Client.OracleParameter.set_Value(Object value)
   at Dapper.DynamicParameters.AddParameters(IDbCommand command, Identity identity) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 4794
   at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action`2 paramReader) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 193
   at Dapper.SqlMapper.<QueryImpl>d__61`1.MoveNext() in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1586
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1479

 

在回頭查看丟進去的查詢物件參數因為包含 bool 屬性,但 Oracle 不支援 bool 參數,故會發生例外錯誤。