基于 SQL DMO 的代码生成器
我已经有一个基于 SQL DMO 的代码生成器,它可以为 SQL Server 2008 数据库中的任何存储过程编写 C# 函数。然而,目前代码生成器只能处理具有输入和输出参数的存储过程。对于返回多条记录的存储过程,代码生成器返回一个数据表,其中的行代表一条输出记录。
如果存储过程的输出是 select * from Member where MemberID=1
,是否可以使用 SQL DMO 来确定存储过程将返回的字段?
谢谢
I already have a code generator based on SQL DMO, that writes the a C# function for any stored procedure in by SQL Server 2008 database. Currenly however the code generator can only handle stored procedures that have input and output parameters. For stored procedures that return multiple records, the code generator returns a datatable with rows that each represent a output record.
Is there a way using SQL DMO to determine the fields that would be returned by a stored procedure if the output of a stored procedure is select * from Member where MemberID=1
?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,你不能在 DMO 中执行此操作,因为 DMO 依赖于存储在 SQL Server 中的元信息,并且 SP 的结果集描述不是以这种方式存储的(据我所知)。
但是,您可以做的是让生成器在 事务中执行存储过程,并分析生成的 SqlDataReader。看看 GetName( )、GetFieldType() 和 < a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getschematable.aspx" rel="nofollow">GetSchemaTable() 方法来构造结果班级。
执行后,回滚事务(以防 SP 对数据库进行任何更改)。
您还可以考虑将生成器升级到 SMO,正如 MSDN 指出 DMO以后将不再支持。
My guess is that you cannot do this in DMO, since DMO relies on meta information stored in SQL Server, and the result set description of an SP is not stored in that way (as far as I know).
What you can do, however, is to have your generator execute the stored procedure inside a transaction, and analyze the resulting SqlDataReader. Have a look at the GetName(), GetFieldType() and GetSchemaTable() methods to construct your result class.
After execution, rollback the transaction (in case the SP makes any changes to the database).
You also might consider upgrading your generator to SMO, as MSDN states that DMO will not be supported in the future.