0

How can I call a stored procedure in Acumatica via PXDataBase which has as input parameter User defined type?

For example, I have the following type:

CREATE TYPE [dbo].[string_list_tblType] AS TABLE(
    [RefNbr] [nvarchar](10) NOT NULL,
    PRIMARY KEY CLUSTERED 
(
    [RefNbr] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
GO

I have the following stored procedure:

CREATE PROCEDURE [dbo].[GetListOfAPInvoices]
    @APInvoices as string_list_tblType readonly,
AS
BEGIN
    select * from APInvoice a where a.RefNbr in (select RefNbr  from @APInvoices)
END

and following fragment of C# code:

    var par = new SqlParameter("APInvoices", dt);
    par.SqlDbType = SqlDbType.Structured;
    par.TypeName = "dbo.string_list_tblType";
    par.UdtTypeName = "dbo.string_list_tblType";
    par.ParameterName = "APInvoices";

    PXSPParameter p1 = new PXSPInParameter("@APInvoices", PXDbType.Udt, par);
    var pars = new List<PXSPParameter> { p1};

    var results = PXDatabase.Execute(sqlCommand, pars.ToArray());

but when I execute my C# code I'm receiving error message:

UdtTypeName property must be set for UDT parameters

When I debugged with reflector class PXSqlDatabaseProvider, method public override object[] Execute(string procedureName, params PXSPParameter[] pars) I noticed that

 using (new PXLongOperation.PXUntouchedScope(Thread.CurrentThread))
                {
                    command.ExecuteNonQuery();
                }

command.Parameters.Items has my method parameters, but item which is related to Udt type is null. I need to know how to pass user defined table type. Has anybody tried this approach?

4

1 回答 1

2

不幸的是,Acumatica 的方法不支持 UDT 参数,并且无法PXDatabase.Execute(..)使用平台的内置功能将参数传递给存储过程。

此外,在编写示例中的数据检索程序时,您应该承认基于 BQL 的数据检索工具在匹配公司掩码、过滤标记为的记录DeletedDatabaseRecord和应用其他一些内部逻辑方面做了大量工作。如果您选择使用包装到存储过程中的普通选择来获取数据,您将绕过所有这些功能。这几乎不是您想要实现的目标。

如果您绝对想使用存储过程从数据库中获取一些记录,但又不想出现上述副作用,那么一种选择是在数据库中创建一个辅助表并使用过程将记录选择到其中。然后在应用程序中添加一个映射到这个新表的 DAC,并使用它通过PXSelect或类似的方式从表中获取数据。

回到您ARInvoice通过数字列表获取一些 s 的特定示例,您可以尝试使用动态 BQL 组合来通过 Acumatica 数据访问工具实现类似的功能。

于 2014-10-02T14:45:51.007 回答