繁体   English   中英

使用this.ExecuteMethodCall在linq to sql中调用存储过程后,全局临时表不再存在

[英]Global temp table doesn't exist any more after calling stored procedure with this.ExecuteMethodCall in linq to sql

首先,我创建了一个调用存储过程的temptable。

然后在尝试从同一个dbcontext获取第二个存储过程的结果时,我收到一条错误,指出临时表不再存在。

这是不完整的代码。

    private void GetTempResult()
    {
        var tempTable = "##mytaemptable";
        //  var task = Task.Factory.StartNew(() =>  Services.StartPreparingTempList(clientId,tempTable));
        // execute stored procedure to create temp table 
        Services.StartPreparingTempList(clientId, tempTable); // temptable gets created successfully here .

        // execute stored procedure to get results from the above created temp table.
        var tempResults = Services.GetPartialTempList(tempTable, jtableArgs); //getting error here . As soon as this statement gets executed the temp table ceases to exist. 
    }

    [global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetPartialTempEmailList")]
    public ISingleResult<JournalEmail> GetPartialTempEmailList([global::System.Data.Linq.Mapping.ParameterAttribute(DbType="NVarChar(MAX)")] string tempTableName, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="Int")] System.Nullable<int> startIndex, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="Int")] System.Nullable<int> maxRowCount)
    {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), tempTableName, startIndex, maxRowCount);
            return ((ISingleResult<JournalEmail>)(result.ReturnValue));
    }

    [global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.StartPreparingTempList")]
    public int StartPreparingTempList([global::System.Data.Linq.Mapping.ParameterAttribute(Name="ClientID", DbType="NVarChar(150)")] string clientID, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="NVarChar(MAX)")] string tempTableName, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="Int")] System.Nullable<int> maxRowCount)
    {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), clientID, tempTableName, maxRowCount);
            return ((int)(result.ReturnValue));
    }
}

使用以下语句在新的连接/会话中执行存储过程吗? 一旦执行此语句,temptable就会停止存在并抛出错误:无效的对象名称。

IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), tempTableName, startIndex, maxRowCount);

有人可以指导我,我错过了什么?

我猜你正在尝试创建一个全局临时表并在一个存储过程中插入值值(让它命名为sp1)并尝试在sp2中检索另一个值(让我们将其命名为sp2)。 在检索第二个存储过程(sp2)时,linqtosql( 在IExecuteResult结果中 )会发生此问题。 我修复了这个问题,但是将dbml文件中的存储过程(sp2)的返回类型更改为我在dbml设计器中创建的列名作为属性类型的类,或者您可以创建具有相同返回类型的视图或表全局临时表并将其添加到设计器中。 然后,您可以使用视图/表作为存储过程的返回类型(sp2)

在图片图示中, sp_EditMVC_reconcile_fix_get_no_medical是(sp2) ,我用它来检索全局临时表, reconcile_no_medical_temp是我创建的类。

在图片说明中* sp_EditMVC_reconcile_fix_get_no_medical是(sp2)*我用来检索全局临时表,* ​​reconcile_no_medical_temp *是我创建的类。

在图片说明中* sp_EditMVC_reconcile_fix_get_no_medical是(sp2)*我用来检索全局临时表,* ​​reconcile_no_medical_temp *是我创建的类。

解决方案2:

我认为它是VS中的一个错误,所以我找不到其中的逻辑,我现在没有时间找到它。

在SP1中添加SP2查询并使用自定义创建的类作为返回类型。 然后SP2将工作。 不知道原因,但如果上述解决方案失败,它将解决它。 对不起,我的英语不好。 希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM