通过Linq-to-SQL调用存储过程时出现异常

时间:2012-02-14 10:04:15

标签: asp.net linq-to-sql exception stored-procedures pluralize

当我的代码尝试执行.dbml文件中存在的存储过程时,我得到以下堆栈跟踪。

  

异常查找传输:System.Data.SqlClient.SqlException:
  无效的对象名称't​​_wfe_user_role'   在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection)
  在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException   exception,Boolean breakConnection)
  在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject)   stateObj)
  在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,   BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject   stateObj)
  在System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
  在System.Data.SqlClient.SqlDataReader.get_MetaData()
  在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,   RunBehavior runBehavior,String resetOptionsString)
  在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior   cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean   异步)
  在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior   cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String   方法,DbAsyncResult结果)
  在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior   cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String   法)
  在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,String method)
  在System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior   行为)
  在System.Data.Common.DbCommand.ExecuteReader()
  at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query,QueryInfo queryInfo,IObjectReaderFactory factory,Object []   parentArgs,Object [] userArgs,ICompiledSubQuery [] subQueries,Object   的lastResult)
  at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query,QueryInfo [] queryInfos,IObjectReaderFactory factory,Object []   userArguments,ICompiledSubQuery [] subQueries)
  在System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression   查询)
  在System.Data.Linq.DataContext.ExecuteMethodCall(对象实例,MethodInfo methodInfo,Object []参数)
  在C:\ Documents中的LinqDataClasses.DataClasses.WorkflowsDataContext.sp_wfe_transfer_task_force(Nullable 1 p_d2_user_ref, Nullable 1 p_d2_diary_ref,Nullable 1 p_state_ref, Nullable 1 p_transfer_ref)   设置\管理员\我的   文档\ SPSM-Bidragshantering_Origo \ SPSM \ MAIN \ CommonData \ LinqDataClasses \数据类\ Workflows.designer.cs:行   347个
  在C:\ Documents and Settings \ Administrator \ My中的SPSM.ContinueWorkflows.ContinueWFs(Int32 [] case,String type)   文档\ SPSM-Bidragshantering_Origo \ SPSM \ MAIN \ SIS \应用程序\ SIS-PreliminaryDecision \ ContinueWorkflows.cs:行   67

我唯一怀疑的是,多元化有一些本身就会被绊倒。数据库中没有名为t_wfe_user_role的表。它被称为t_wfe_user_roles,但随后Linq在t_wfe_user_role文件的GUI中将其重命名为.dbml。该表是一个带有两个外键的连接表。

任何想法!?

这是我调用存储过程的代码片段。调用结束时(sp_wfe_transfer_task_force):

public class ContinueWorkflows
{
    public AppVariables _APPVARS = new Utility.AppVariables();
    public void ContinueWFs(int[] cases, string type)
    {
        foreach (int Case in cases)
        {
            if (Case != 0)
            {
                _APPVARS = (Utility.AppVariables)System.Web.HttpContext.Current.Session["CommonAppVariables"];
                LinqDataClasses.DataClasses.WorkflowsDataContext wfdc = new LinqDataClasses.DataClasses.WorkflowsDataContext(_APPVARS.SQLConnectionString);
                LinqDataClasses.DataClasses.t_wfe_workflow wf = wfdc.t_wfe_workflows.Where(p => p.c_d2_case_ref == Case && p.c_cancelled != true).FirstOrDefault();
                if (wf != null)
                {
                    LinqDataClasses.DataClasses.t_wfe_state state = wfdc.t_wfe_states.Where(p => p.c_workflow_ref == wf.c_rowid && p.c_cancelled != true).FirstOrDefault();
                    if (state != null)
                    {
                        LinqDataClasses.DataClasses.t_wfe_transfer transfer;
                        if (type == "Beslut")
                        {
                            transfer = wfdc.t_wfe_transfers.Where(p => p.c_from_step_ref == state.c_step_ref && p.c_name == "Till beslut" && p.c_cancelled != true).FirstOrDefault();
                            if (transfer == null)
                            {
                                transfer = wfdc.t_wfe_transfers.Where(p => p.c_from_step_ref == state.c_step_ref && p.c_name == "Övergång direkt till beslut" && p.c_cancelled != true).FirstOrDefault();
                            }
                            if (transfer == null)
                            {
                                transfer = wfdc.t_wfe_transfers.Where(p => p.c_from_step_ref == state.c_step_ref && p.c_name == "Övergång till beslut" && p.c_cancelled != true).FirstOrDefault();
                            }
                        }else if (type == "BVS")
                        {
                            transfer = wfdc.t_wfe_transfers.Where(p => p.c_from_step_ref == state.c_step_ref && p.c_name == "Stopp" && p.c_cancelled != true).FirstOrDefault();
                        }
                        else if (type == "TUFF")
                        {
                            transfer = wfdc.t_wfe_transfers.Where(p => p.c_from_step_ref == state.c_step_ref && p.c_name == "Preliminärt besked" && p.c_cancelled != true).FirstOrDefault();
                        }
                        else // SIS Prel Besked
                        {
                            transfer = wfdc.t_wfe_transfers.Where(p => p.c_from_step_ref == state.c_step_ref && p.c_name == "Övergång till preliminärt besked" && p.c_cancelled != true).FirstOrDefault();
                        }
                        if (transfer != null)
                        {
                            //Do transfer
                            int transref = transfer.c_rowid;
                            wfdc.sp_wfe_transfer_task_force(1, _APPVARS.DiaryRef, state.c_rowid, transref);
                        }
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果重新生成数据模型没有问题,那么您可以关闭复数和生成类。 在视觉工作室 在“工具”菜单上,单击“选项”。

In the Options dialog box, expand Database Tools.

(注意:如果“数据库工具”节点不可见,请选择“显示所有设置”。)

Click O/R Designer.

Set Pluralization of names to Enabled = False to set the O/R Designer so that it does not change class names.

Set Pluralization of names to Enabled = True to apply pluralization rules to the class names of objects added to the O/R Designer.

,否则 您可以通过右键单击dbml设计器窗口中的表并选择属性来更改生成的名称。有一个名为“name”的字段,您可以使用该字段定义自定义名称。