|
|
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类型的映射集旋转,映射集为
|
|
|
A B · C#Excel自动调整列避免长文本时出错 8 月前 |
|
|
Megrez7 · C#ToArray转换合并为一行,导致数组元素更改 8 月前 |
|
Aycon · 在工厂方法中释放部分创建的对象的正确方法是什么? 8 月前 |
|
|
Sei · Avalonia/WPF将路由器传递到控制模板 9 月前 |