如何调用复合类型

时间:2018-03-13 14:19:19

标签: vb.net postgresql npgsql

我想知道如何使用Npgsql调用复合类型,我使用vb。 这将是代码,从类型:

开始
CREATE TYPE public.type_detalle_ac AS
(
  id_componente integer,
  precio numeric(10,2),
  cantidad integer,
  sub_total numeric(10,2)
);

这将是功能:

CREATE OR REPLACE FUNCTION public.sp_adm_artefacto(
v_serie character varying DEFAULT NULL::character varying,
v_tipo_artefacto integer DEFAULT NULL::integer,
v_modelo character varying DEFAULT NULL::character varying,
v_marca integer DEFAULT NULL::integer,
v_detalle type_detalle_ac DEFAULT NULL::type_detalle_ac,
v_usuario integer DEFAULT NULL::integer,
v_id_artefacto integer DEFAULT NULL::integer,
v_tipo_operacion character DEFAULT NULL::bpchar)
RETURNS void
LANGUAGE 'plpgsql'

COST 100
VOLATILE 
ROWS 0
AS $BODY$

DECLARE 

    VL_ID_ARTEFACTO INTEGER;
    VL_ID_DETALLE_AC INTEGER;
BEGIN
    IF V_TIPO_OPERACION = 'I' THEN

        SELECT COALESCE(MAX(ID_ARTEFACTO),0) INTO VL_ID_ARTEFACTO FROM ARTEFACTO;
        VL_ID_ARTEFACTO:=VL_ID_ARTEFACTO+1;

        INSERT INTO ARTEFACTO (ID_ARTEFACTO,SERIE,TIPO_ARTEFACTO,MODELO,MARCA,USUARIO_CREACION,FECHA_CREACION)
        VALUES (VL_ID_ARTEFACTO,v_serie,v_tipo_artefacto,v_modelo,v_marca,V_USUARIO,NOW());

        SELECT COALESCE(MAX(ID_DETALLE_AC),0) INTO VL_ID_DETALLE_AC FROM DETALLE_AC;
        VL_ID_DETALLE_AC:=VL_ID_DETALLE_AC+1;

        INSERT INTO DETALLE_AC(ID_DETALLE_AC,ID_ARTEFACTO,ID_COMPONENTE,PRECIO,CANTIDAD,SUB_TOTAL,
                               USUARIO_CREACION,FECHA_CREACION)
        SELECT VL_ID_DETALLE_AC,VL_ID_ARTEFACTO,ID_COMPONENTE,PRECIO,CANTIDAD,SUB_TOTAL,v_usuario,NOW()
        FROM (SELECT V_DETALLE.*) AS V_DETALLE;
        --VALUES (VL_ID_DETALLE_AC,VL_ID_ARTEFACTO,V_DETALLE.ID_COMPONENTE,V_DETALLE.PRECIO,V_DETALLE.CANTIDAD,V_DETALLE.SUB_TOTAL,v_usuario,NOW());


    END IF;

END;


$BODY$;

现在在vb中,从类代码开始:

Public Class E_DETALLE_AC
   Public Property id_componente As Integer

   Public Property precio As Decimal
   Public Property cantidad As Integer
   Public Property sub_total As Decimal
End Class

我试图用MapCompositeGlobally以下面的方式调用它,但我不能:

Sub ADMINISTRAR_ARTEFACTO(ByVal P As E_ARTEFACTO, ByVal LD As List(Of E_DETALLE_AC))
    NpgsqlConnection.MapCompositeGlobally(Of List(Of E_DETALLE_AC))("type_detalle_ac")
    Dim CONECTION As New NpgsqlConnection


    Try
        CONECTION.ConnectionString = "Host=localhost;Username=postgres;Password=123;Database=ALURHE_DB"
        Dim COMMAND As New NpgsqlCommand
        With COMMAND
            .Connection = CONECTION
            .CommandType = CommandType.StoredProcedure
            .CommandText = "SP_ADM_ARTEFACTO"

            .Parameters.AddWithValue("v_serie", P.P_SERIE)
            .Parameters.AddWithValue("v_tipo_artefacto", P.P_TIPO_ARTEFACTO)
            .Parameters.AddWithValue("v_modelo", P.P_MODELO)
            .Parameters.AddWithValue("v_marca", P.P_MARCA)

            .Parameters.AddWithValue("v_detalle", LD)
            .Parameters.AddWithValue("v_usuario", P.P_USUARIO)
            .Parameters.AddWithValue("v_id_artefacto", If(P.P_TIPO_OPERACION = "M", P.P_ID_ARTEFACTO, DBNull.Value))
            .Parameters.AddWithValue("v_tipo_operacion", P.P_TIPO_OPERACION)

            End With


        CONECTION.Open()

        COMMAND.ExecuteNonQuery()
        CONECTION.Close()

    Catch ex As Exception
        If (CONECTION.State = ConnectionState.Open) Then
            CONECTION.Close()
        End If

        Throw ex
    End Try
End Sub

我收到以下错误:

  

PostgreSQL复合类型public.type_detalle_ac包含字段id_componente,它无法匹配任何CLR类型List`1

我能做什么? Npgsql支持列表吗?

0 个答案:

没有答案