지원 방법이 있는지 모르겠지만 Dapper가 문자열 매개 변수 값을 사용중인 것으로 보이는 Postgresql citext 데이터 유형에 매핑하는 데 문제가 있습니다. 텍스트 형 특히 Dapper 및 Postgresql-citext 데이터 유형 사용
, 나는 citext의 매개 변수를받는 함수를 호출하려고 해요 - 내가 돌아올 오류 것은 :var c = ConnectionManager<T>.Open();
string sql = @"select * from ""dbo"".""MyFunction""(@schemaName, @tableName);";
var param = new
{
schemaName = schema,
tableName = table
};
string insecureSalt = c.QueryMultiple(sql, param).Read<string>().FirstOrDefault();
ConnectionManager<T>.Close(c);
Error: Npgsql.PostgresException: 42883: function dbo.MyFunction(text, text) does not exist.
일치합니다 서명 기능의 dbo.MyFunction입니다 (citext, citext) 그래서 그것은 분명히 기본 매핑을 사용하여 찾을 수 없습니다.
Npgsql - http://www.npgsql.org/doc/types.html에 따르면 형식으로 NpgsqlDbType.Citext를 지정할 수 있어야하지만 Dapper를 사용하여이 작업을 수행 할 수있는 방법을 찾을 수 없습니다.
는 셰이에서 여기에 완벽한 솔루션을 대답 덕분에 해결 : 당신은 아마 ICustomQueryParameter를 확장하는 CitextParameter을 만들 만들 필요가
var c = ConnectionManager<T>.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<string>().FirstOrDefault();
ConnectionManager<T>.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
});
}
}
이 완벽 당신을 감사 작동하는 경우, 당신은 다음과 같은 쿼리를 변경하고 볼 수 있습니다 (USR는 클래스 객체이다)! 이것에 구글 히트 곡이 없었기 때문에 영원히 찾아 낼 수있었습니다. –