如何确定在C#中的数据访问层存储过程的输出参数大小属性 [英] How to determine size property for stored procedure output parameters in C# data access layer

查看:131
本文介绍了如何确定在C#中的数据访问层存储过程的输出参数大小属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了无耻模仿过的城堡项目的ActiveRecord的实现数据访问层。为了使它获得认可,就必须支持使用存储过程的丰富的图书馆我的组织,这已写入使用每个输入/输出结构可以想象,包括返回值和每一个可以想象的数据类型的输出参数。

I've made a data access layer modeled shamelessly off of Castle Project's ActiveRecord implementation. In order for it to gain acceptance, it must support the extensive library of stored procedures in use at my organization, which have been written to use every input/output structure imaginable, including return values and output parameters of every conceivable datatype.

我的问题是发展中的code,增加了输出参数,用于执行存储过程的Command对象的参数集合。现在,我只是用一个大的默认值,希望它足以捕获所有的情况,但这种感觉以次充好。

My problem is in developing the code that adds the output parameter to the parameters collection of the Command object used to execute the stored procedure. Right now I'm just using a large default value, hoping it's enough to catch all the cases, but this feels shoddy.

我怎么能知道输出参数的长度提前?

How can I know the length of the output parameter in advance?

下面是我的DAL类,使用属性来表示输出参数:

Here's my DAL class, using attributes to denote the output parameter:

 [StoredProcedure("usp_PostARTransaction", OperationType.Insert)]
    public class ARTranPost : DataObjectBase<ARTranPost>
    {
        [StoredProcedureParameter("sARTranID",OperationType.Insert,ParameterDirection.Output)]
        public string ARTranID {get;set;}
        [StoredProcedureParameter("sDueDate", OperationType.Insert, ParameterDirection.Input)]
        public string DueDate { get; set; }
        [StoredProcedureParameter("sPostDate", OperationType.Insert, ParameterDirection.Input)]
        public string PostDate { get; set; }

    }

我是否需要使用SMO或其他一些库获取的长度从数据库中?

Do I need to use SMO or some other library to get the length from the database?

推荐答案

如果你工作的SQL Server(在OP未指定),则可以使用系统对象和SYSCOLUMNS目录视图来检索存储过程和它们的参数:

If you work on SQL Server (not specified in OP), you can use the sysobjects and syscolumns catalog views to retrieve stored procedures and their parameters:

SELECT p.name, t.name, c.*
FROM sysobjects p
INNER JOIN syscolumns c ON p.id = c.id
INNER JOIN systypes t on c.xusertype = t.xusertype
WHERE p.type = 'P'
AND p.name NOT LIKE 'dt[_]%'
ORDER BY p.name, c.colid

(在SQL2005 +使用sys.objects中,sys.types和SYS.COLUMNS,但上了年纪的看法仍然存在)

(in SQL2005+ use sys.objects, sys.types and sys.columns, but the older views are still there)

这让你的SP名称,类型名称,参数名称,长度和输入/输出方向(c.isoutparam)。

This gives you the SP name, type name, parameter name, length, and input/output direction (c.isoutparam).

我写在我的博客上的对于C#产生SP的接入。我没有覆盖OUT参数存在,但调整code输出参数应该是简单的。

I wrote on my blog on generating SP access for C#. I did not cover OUT parameters there, but adjusting the code to output parameters should be straightforward.

这篇关于如何确定在C#中的数据访问层存储过程的输出参数大小属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆