2011-06-02 54 views
3

我有一个存储的过程,我们正在使用它来简单地将新记录插入到各个表中。此存储过程设置为不返回任何内容才执行。当我将它放入我的DBML中时,它将其设置为“无效”,我认为它是正确的。这是DMBL自动生成的代码。存储过程不会也不应该返回任何错误结果

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.sp_PTS_Action_Insert_Comment")] 
     public void sp_PTS_Action_Insert_Comment([global::System.Data.Linq.Mapping.ParameterAttribute(Name="Form_Name", DbType="VarChar(20)")] string form_Name, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Form_Number", DbType="VarChar(25)")] string form_Number, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="UID", DbType="VarChar(15)")] string uID, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Cmt", DbType="VarChar(200)")] string cmt) 
     { 
      this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), form_Name, form_Number, uID, cmt); 
     } 
    } 

我把这个SP如下:

_context.sp_PTS_Action_Insert_Comment(formInformation["formType"], formInformation["formNumber"], userId, comment); 

当这个代码执行,它抛出一个错误说

“系统太虚不是一个有效的返回类型 对映射存储过程“

我的问题是你可以使用linq to St与SP的过程故意不返回任何东西?如果是这样的话,我在这个例子中做错了什么?

+0

分享。 http://stackoverflow.com/questions/3193583/strange-system-void-return-exception-generated-when-running-a-mapped-stored-proce – 2011-06-02 19:29:31

回答

1

我不确定为什么,当放置一个不返回任何东西的程序时,Linq会生成上面的void函数,因为它会抛出'不是有效的返回类型'错误。

为了解决这个问题,我使用SCOPE_IDENTITY()作为返回值来添加对过程的返回,所以我可以在我的代码中使用它。

希望有所帮助。