title: Using Dapper and Postgresql - citext data type
body: <p>I'm not sure if there is a way to support this, but I'm having trouble getting Dapper to map string parameter values to the Postgresql citext data type as it seems to be using the text type.</p>
  
  <p>In particular, I'm trying to call a function that takes in citext parameters - the error I get back is:</p>
  
  <pre><code>var c = ConnectionManager&lt;T&gt;.Open();
  string sql = @"select * from ""dbo"".""MyFunction""(@schemaName, @tableName);";
  var param = new
  {
      schemaName = schema,
      tableName = table
  };
  
  string insecureSalt = c.QueryMultiple(sql, param).Read&lt;string&gt;().FirstOrDefault();
  ConnectionManager&lt;T&gt;.Close(c);
  
  Error: Npgsql.PostgresException: 42883: function dbo.MyFunction(text, text) does not exist.
  </code></pre>
  
  <p>The signature that would match is function dbo.MyFunction(citext, citext) so clearly it can't find it using the default mapping.</p>
  
  <p>According to Npgsql - <a href="http://www.npgsql.org/doc/types.html" rel="nofollow">http://www.npgsql.org/doc/types.html</a> I need to be able to specify NpgsqlDbType.Citext as the type but I can't find a way to do this using Dapper.</p>
  
  <p><strong>Solved</strong> thanks to answer from Shay, complete solution here:</p>
  
  <pre><code>var c = ConnectionManager&lt;T&gt;.Open();
  string sql = @"select * from ""dbo"".""MyFunction""(@schemaName, @tableName);";
  var param = new
  {
      schemaName = new CitextParameter(schema),
      tableName = new CitextParameter(table)
  };
  
  string insecureSalt = c.QueryMultiple(sql, param).Read&lt;string&gt;().FirstOrDefault();
  ConnectionManager&lt;T&gt;.Close(c);
  
  public class CitextParameter : SqlMapper.ICustomQueryParameter
  {
      readonly string _value;
  
      public CitextParameter(string value)
      {
          _value = value;
      }
  
      public void AddParameter(IDbCommand command, string name)
      {
          command.Parameters.Add(new NpgsqlParameter
          {
              ParameterName = name,
              NpgsqlDbType = NpgsqlDbType.Citext,
              Value = _value
          });
      }
  }
  </code></pre>