|
|
1
3
“sticky bit”提出的建议纠正了问题。我在下面为可能处理相同问题的任何其他人提供了更新的示例代码。所有字符串都使用“ToLower()”转换为小写,但这仅是在“NpgsqlConnection”中映射数据库类型所必需的。MapCompositeGlobal’。
namespace TestDatabase
{
public class MyType
{
public float X;
public float Y;
};
public class TestCompositeType
{
public void Test()
{
NpgsqlConnection.MapCompositeGlobally<TestDatabase.MyType>( "MySchema.MyType".ToLower() );
var connection = new NpgsqlConnection( "Host=localhost;Username=postgres;Password=123456;database=testdb".ToLower() );
if( null == connection )
throw new NullReferenceException( "connection" );
try
{
connection.Open();
var cmd = new NpgsqlCommand( "MySchema.SetMyType".ToLower(), connection );
cmd.CommandType = System.Data.CommandType.StoredProcedure;
var par = new NpgsqlParameter( "ItemID2".ToLower(), NpgsqlDbType.Integer );
par.Value = 1;
cmd.Parameters.Add( par );
par = new NpgsqlParameter( "MyType2".ToLower(), NpgsqlDbType.Composite );
MyType myType = new MyType();
myType.X = 1;
myType.Y = 2;
par.Value = myType;
par.SpecificType = typeof( MyType );
cmd.Parameters.Add( par );
int id = Convert.ToInt32( cmd.ExecuteScalar() );
}
finally
{
connection.Close();
}
}
}
}
|
|
2
2
通话前
(
此外,必须设置属性
都解释过了 "Accessing PostgreSQL Enums and Composites" 。 显然,在Npgsql的4.0版本中会变得更容易。我自己用Npgsql版本3.2.7 BTW测试了它。 编辑:
另一种解决方案是不指定
然后,右Postgres类型由C#类型到Prostgres类型的映射集旋转,映射集为
|
|
|
Johnny T · 基于当前值的SQL合并表[重复] 1 年前 |
|
|
Peter Schofield · 类型转换Postgresql 1 年前 |
|
|
Kevin Smeeks · Pyspark JDBC分区读取 1 年前 |
|
|
Andrus · 如何在sql中查找第二个匹配项 1 年前 |