Repository navigation
Open
Description
Following this issue MiniProfiler/dotnet#319 . The problem is still there.
When changing
IDbConnection connection = new NpgsqlConnection(connectionString);
to
IDbConnection connection = new StackExchange.Profiling.Data.ProfiledDbConnection(new NpgsqlConnection(connectionString), MiniProfiler.Current);
Queries containing Any() fails with following error:
Npgsql.PostgresException
HResult=0x80004005
Message=42809: op ANY/ALL (array) requires array on right side
Source=Npgsql
StackTrace:
at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlDataReader.<NextResult>d__46.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.<ExecuteDbDataReader>d__100.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\dotnet\src\MiniProfiler.Shared\Data\ProfiledDbCommand.cs:line 205
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1064
at Dapper.SqlMapper.<QueryImpl>d__138`1.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1081
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
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 C:\projects\dapper\Dapper\SqlMapper.cs:line 723
...
Sample query: SELECT * FROM public."tblcars" WHERE "Id"=ANY(@Ids);
private IDbConnection OpenConnection(string connectionString)
{
IDbConnection connection = new StackExchange.Profiling.Data.ProfiledDbConnection(new NpgsqlConnection(connectionString), MiniProfiler.Current);
// IDbConnection connection = new NpgsqlConnection(connectionString);
connection.Open();
return connection;
}
public IEnumerable<Car> Get(int[] ids)
{
string query = $"SELECT * FROM public.\"tblCar\" WHERE \"Id\"=ANY(@Ids);";
using (IDbConnection connection = OpenConnection(this.ConnectionString))
{
return connection.Query<Car>(query, new { Ids = ids }).ToList();
}
}
Reacted by Felix, Mantas Jarašūnas and 喵喵喵
Metadata
Metadata
Assignees
Labels
No labels
Activity
znyet commentedon Jan 7, 2019
you can do like this
NinoFloris commentedon May 7, 2019
@NickCraver hitting this during testing with miniprofiler as well.
Found out why:
Going through
https://github.com/StackExchange/Dapper/blob/68eea4ff2629e9cc9e36ed6a996b4eebc5a4f87a/Dapper/SqlMapper.cs#L1970-L1975
Found a call to
FeatureSupport.Get(command.Connection).ArraysWhich is defined here https://github.com/StackExchange/Dapper/blob/4e62055c5775aced61b848282ed180de0ab62161/Dapper/FeatureSupport.cs#L19-L24
Where it tries to grab the connection type name. Which obviously in the case of a ProfileDbConnection won't be NpgsqlConnection.
Seems you'd have to choose between:
As everything coming out of ProfileDbConnection is wrapped or might incur a database call I don't see pretty solutions to fingerprinting the NpgsqlConnection via any DbConnection methods without adding knowledge of ProfileDbConnection.
EDIT:
Or you have to do changes on the MiniProfiler side to have
ProfiledDbCommand.DbConnectionreturn underlying connection instead. That could be quite unexpected and messy too though.https://github.com/MiniProfiler/dotnet/blob/master/src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs#L139-L147
NinoFloris commentedon May 7, 2019
We'll be running with this temporary fix for now
NinoFloris commentedon Jul 25, 2019
@mgravell any way we can help on this?
rwasef1830 commentedon May 18, 2023
Here's a simple workaround for people suffering from this: