Is it possible to take a SQLParameter object and have it spit out a sql variable declaration in the c# layer?

73 views Asked by At

Note: This is just for debugging assistance, this isn't going to go into production, I'm just finding I have a slow workflow and I'd like to if possible speed it up

I am doing some debugging in a .net application that uses some table valued sql parameters. I want to generate SQL code from the c# layer to throw into SSMS for debugging purposes. It should be noted, I do not want the exact text of the EF-Generated SQL query, but rather I want sql that will define and populate corrosponding sql variables for my sqlparameter objects.

Right now I just have a "generate sql" function that does a lot of string concatenation, but every time I refactor a sql table type or add a new argument I have to update that string function -- it's not very robust and keeping it in sync with my refactors is slowing me down considerably.

I'd rather just pass a list of sqlParameter objects and get a string back that has all the declarations and variable setting. Is there a native way to take a SQL parameter variable and get back something like

DECLARE @SomeVar SQLTableType
INSERT INTO @SomeVar VALUES ('foo', 'bar')
INSERT INTO @SomeVar VALUES ('baz', 'buz')

or in the case of a scalar variable

DECLARE @SomeOtherVar varchar(100)
set @SomeOtherVar = 'ThisIsAValue'
0

There are 0 answers