title: Entity framework stored procedure issue
body: <p>I have following stored procedure defined:</p>
  
  <pre><code>USE [BcmMetrice]
  GO
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER PROCEDURE [dbo].[ActivityAdd_proc] @Name nvarchar(max),@Description nvarchar(max)  =null ,@Users nvarchar(max),@Object_id nvarchar (15) =null, @Source nvarchar(10)  =null, @TemplateId bigint  =null, @UserID bigint =null
  AS
  
  
  DECLARE activityUsers_cursor CURSOR FOR
  select s from dbo.SplitString(@Users, ';')
  
  
  DECLARE
  @new_ActivityId bigint,
  @new_CommentId bigint,
  @activityUser_l bigint
  
  BEGIN TRY
  
  INSERT INTO [BcmMetrice].[dbo].[Activity]
             ([Name]
             ,[Description]
             ,[Type]
             ,[Created])
       VALUES
             (@Name
             ,@Description
             ,ISNULL(@TemplateId,0)
             ,GETDATE())
  
  SET @new_ActivityId = (SELECT SCOPE_IDENTITY())
  
  INSERT INTO [BcmMetrice].[dbo].[Comment] ([UserID],[CommentText],[Timestamp])
  VALUES (ISNULL(@UserID,151),'Activity has been created',GETDATE())
  
  SET @new_CommentId = (SELECT SCOPE_IDENTITY())
  
  INSERT INTO [BcmMetrice].[dbo].[ActivityComment] ([ActivityID],[CommentID])
  VALUES (@new_ActivityId, @new_CommentId)
  
  INSERT INTO [BcmMetrice].[dbo].[Log]([Timestamp],[Type],[Data],[StackTrace]) VALUES (GETDATE(),'SQL.ActivityAdd_proc','users='+ISNULL(CAST(@Users as varchar(max)),'empty'),null)
  
  OPEN activityUsers_cursor
  FETCH NEXT FROM activityUsers_cursor INTO @activityUser_l
  WHILE @@FETCH_STATUS = 0
      BEGIN
  
          INSERT INTO [BcmMetrice].[dbo].[Log]([Timestamp],[Type],[Data],[StackTrace]) VALUES (GETDATE(),'SQL.ActivityAdd_proc','Inserting users='+ISNULL(CAST(@activityUser_l as varchar(max)),'empty'),null)
  
          INSERT INTO [BcmMetrice].[dbo].[ActivityUser]
                 ([ActivityId]
                 ,[UserId]
                 ,[Role])
           VALUES
                 (@new_ActivityId
                 ,@activityUser_l
                 ,1)
  
          FETCH NEXT FROM activityUsers_cursor INTO @activityUser_l
      END
  
  CLOSE activityUsers_cursor
  DEALLOCATE activityUsers_cursor
  
  END TRY
  
  BEGIN CATCH
  
  PRINT 'ERROR'
  INSERT INTO [BcmMetrice].[dbo].[Log]([Timestamp],[Type],[Data],[StackTrace]) VALUES (GETDATE(),'SQL.ActivityAdd_proc','ERROR CATCHED!'+ERROR_MESSAGE(),null)
  
  
  END CATCH
  
  select @new_ActivityId
  </code></pre>
  
  <p>The thing I would like to do is to return from the procedure the id of a newly added activity. That is why at the very and I use line:</p>
  
  <pre><code>select @new_ActivityId
  </code></pre>
  
  <p>When testing this procedure in SQL Management Studio everything seems to be working fine. Problem starts when I try to use this procedure in my .NET project. I updated my edmx model form database, but when I execute this procedure the return value is invalid.</p>
  
  <p>Procedure execution looks like this:</p>
  
  <pre><code>int ret = dc.Db.ActivityAdd_proc(name, description, users, object_id, source, templateId, userId);
  </code></pre>
  
  <p>Does anyone have an idea what I might be doing wrong?</p>