title: Inheriting from System.Data.Common.DbCommand, Parameters property is null
body: <p>I'm busy building a custom framework for data retrieval and serialization and I'm running into a problem when defining a proprietary database connection/command/parameter combo. Everything works as expected until I try and add parameters to my custom command object. I have a base class that handles query preparation and execution with a generic function as follows:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Prepares a command for execution.
  /// &lt;/summary&gt;
  /// &lt;typeparam name="C"&gt;The type of command to prepare&lt;/typeparam&gt;
  /// &lt;typeparam name="P"&gt;The type of parameters to add to the command&lt;/typeparam&gt;
  /// &lt;param name="query"&gt;The query to be prepared for the command&lt;/param&gt;
  /// &lt;param name="parameters"&gt;Dictionary of parameters to be added to the command&lt;/param&gt;
  /// &lt;returns&gt;A prepared command to execute against a database&lt;/returns&gt;
  protected virtual C Prepare&lt;C, P&gt;(string query, Dictionary&lt;string, object&gt; parameters)
      where C : DbCommand, new()
      where P : DbParameter, new()
  {
      if (Connection == null)
          throw new System.Exception("Database connector hasn't been initialized yet. Call .Initialize() first.");
      C command = new C()
      {
          CommandText = query,
          Connection = Connection
      };
      if (parameters != null)
      {
          foreach (KeyValuePair&lt;string, object&gt; kvp in parameters)
          {
              command.Parameters.Add(new P() // &lt;-- Breaks right here!
              {
                  ParameterName = kvp.Key,
                  Value = kvp.Value
              });
          }
          parameters = null;
      }
      return command;
  }
  </code></pre>
  
  <p>I have classes implemented for most of the provider types (Ole, ADO, ODBC, Oracle, etc), but they are based off the standard .NET types provided in the <code>System.Data</code> namespace. I now have a completely custom class that inherits from <code>System.Data.Common.DbCommand</code> that I want to use, but when I try and add parameters (in the <code>Prepare</code> function above) to this new class, I see the <code>Parameters</code> property of my new class is <code>null</code>! It is inherited from the base class and is set to read only, so I can't initialize it on my own. My class is defined as follows:</p>
  
  <p><code>public sealed class Connection : System.Data.Common.DbConnection</code></p>
  
  <p>I've tried explicitly overriding the property in my class as <code>public new List&lt;Parameter&gt; Parameters { get; set; }</code> but to no avail - the generic function still uses the base class' <code>Parameters</code> property. The only way to get a handle on the overridden property is to explicitly cast <code>command</code> (in the <code>Prepare</code> function) to my custom type, which is obviously what I don't want to do.</p>
  
  <p>Am I missing something here?</p>