Thursday 19 September 2013

how to set return type of a stored procedure according to a specific table

how to set return type of a stored procedure according to a specific table

I had made a dynamic stored procedure like this
CREATE PROCEDURE [dbo].[MyProcedure]
@pSelect nvarchar(max)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SQL nvarchar(max)
SET @SQL = 'select ' + @pSelect + ' from tabel1';
EXEC (@SQL)
END
And on updating my entitydatamodel the in context.cs the above stored
procedure is in the form of
virtual int MyProcedure(string pSelect)
{
var pSelectParameter = pSelect != null ?
new ObjectParameter("pSelect", pSelect) :
new ObjectParameter("pSelect", typeof(string));
return
((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("MyProcedure",
pSelectParameter);
}
on calling the stored procedure from c# code
var result = myDataModel.MyProcedure("Select * From table1").tolist();
the above code is showing error because MyProcedure is returning a integer
return type
so how could i set the return type of the stored procedure according to
tje select query I am passing to it

HOW DO I MODIFY MY STORED PROCEDURE SO THAT ITS RETURN TYPE IS OF ANY
SPECIFIC TABLE TYPE

No comments:

Post a Comment