gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:28:51 25 4
gpt4 key购买 nike

首先,我创建了一个调用存储过程的 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));
}
}

是否使用以下语句在新的连接/ session 中执行存储过程?一旦执行此语句,temptable 将不复存在并抛出错误:对象名称无效。

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

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

最佳答案

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

In the picture illustration sp_EditMVC_reconcile_fix_get_no_medical is (sp2) which I used to retrieve the global temp table and reconcile_no_medical_temp is the class I created.

In the picture illustration *sp_EditMVC_reconcile_fix_get_no_medical is (sp2)* which I used to retrieve the global temp table and *reconcile_no_medical_temp* is the class I created.

In the picture illustration *sp_EditMVC_reconcile_fix_get_no_medical is (sp2)* which I used to retrieve the global temp table and *reconcile_no_medical_temp* is the class I created.

解决方案 2:

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

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

关于c# - 在 linq to sql 中使用 this.ExecuteMethodCall 调用存储过程后,全局临时表不再存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24059556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com