Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Npgsql;
- using NpgsqlTypes;
- using System;
- using System.Data;
- namespace NPgSqlTest
- {
- class Program
- {
- /*
- -- object definitions in the database
- CREATE TYPE xy
- AS (x real,
- y real);
- CREATE FUNCTION public.fxy(_xy xy)
- RETURNS real
- AS
- $$
- BEGIN
- RETURN _xy.x + _xy.y;
- END;
- $$
- LANGUAGE plpgsql;
- */
- public class XY
- {
- public float x;
- public float y;
- public XY()
- {
- }
- }
- static int Main(string[] args)
- {
- NpgsqlConnection.MapCompositeGlobally<XY>("public.xy");
- try
- {
- using (NpgsqlConnection connection = new NpgsqlConnection("Host=*; Port=*; Database=*; Username=*; password=*;"))
- {
- connection.Open();
- using (NpgsqlCommand command = connection.CreateCommand())
- {
- command.CommandType = CommandType.StoredProcedure;
- command.CommandText = "fxy";
- NpgsqlParameter parameter = new NpgsqlParameter("_xy", NpgsqlDbType.Composite);
- XY xy = new XY();
- xy.x = 7;
- xy.y = 10;
- parameter.Value = xy;
- // commenting the following line out I get the exception
- // when I uncomment it, the exception is gone and everythings works fine
- //parameter.SpecificType = typeof(XY);
- command.Parameters.Add(parameter);
- Console.Out.WriteLine(command.ExecuteScalar());
- }
- }
- }
- catch (Exception exception)
- {
- Console.Error.WriteLine(exception);
- Console.Error.WriteLine();
- }
- Console.Out.WriteLine("DONE");
- Console.In.Read();
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement