Skip to content

Overriding Parameters property of SqliteCommand does not work #27706

@BitEater21

Description

@BitEater21

Description

For a special case I want to use a derivation from SqliteParameterCollection to be used in a derivation of SqliteCommand. For this I override the virtual Parameters property of SqliteCommand.

If doing so I get an exception when a command uses parameters (see stack trace).
When I add the parameters also to be base class parameters, it works fine.
It seems the SqliteCommand does not use the property for internal access to the collection. But if so, I don't see why the property itself is virtual?!

Include your code

public class MySqliteParameterCollection : SqliteParameterCollection
{
   // some methods here...
}

public class MySqliteCommand : SqliteCommand
{
    private MySqliteParameterCollection parameters;

    public override SqliteParameterCollection Parameters
        => this.parameters ??= new MySqliteParameterCollection();

    // some methods here...
}

Include stack traces

System.InvalidOperationException: Must add values for the following parameters: @key, @value
   at Microsoft.Data.Sqlite.SqliteCommand.GetStatements(Stopwatch timer)+MoveNext()
   at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()

Include version information

Microsoft.Data.Sqlite version: 6.03
Target framework: .NET 5.0
Operating system: Windows 10 64 Bit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions