Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 全局临时表没有';在linq to sql中使用this.ExecuteMethodCall调用存储过程后,将不再存在_C#_.net_Sql Server 2008_Linq To Sql - Fatal编程技术网

C# 全局临时表没有';在linq to sql中使用this.ExecuteMethodCall调用存储过程后,将不再存在

C# 全局临时表没有';在linq to sql中使用this.ExecuteMethodCall调用存储过程后,将不再存在,c#,.net,sql-server-2008,linq-to-sql,C#,.net,Sql Server 2008,Linq To Sql,首先,我创建了一个诱人的调用存储过程的方法 然后,当尝试从同一dbcontext中的第二个存储过程获取结果时,我收到一个错误,表示临时表不再存在 这是不完整的代码 private void GetTempResult() { var tempTable = "##mytaemptable"; // var task = Task.Factory.StartNew(() => Services.StartPreparingTempList(

首先,我创建了一个诱人的调用存储过程的方法

然后,当尝试从同一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));
    }
}

有人能告诉我我遗漏了什么吗?

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

在图片插图中,我使用sp_EditMVC_reconcil_fix_get_no_medical is(sp2)检索全局临时表,而reconcil_no_medical_temp是我创建的类

解决方案2:

我认为这是VS中的一个bug,所以我找不到其中的逻辑,现在也没有时间去查找

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

为什么要在linq to sql中创建临时表?导入视图可能更好?如果两个单独的会话同时执行,会发生什么情况?不知道为什么它对你不起作用,但基本上是因为我会移动几座大山,以避免一开始就必须这样做。问题可能出在存储过程本身…@Arion,想将临时结果存储在某个地方…,我想到了这一点。现在进行概念验证以在以后获得部分结果可能会改变存储。导入视图可能会更好。我没有太多想法:)@Tony,现在不需要担心会话。只想看到功能正常工作。当我在从应用程序调用存储的过程之前,用硬编码的值来执行存储的过程时,它会正常运行。有趣的是,如果在不同的会话中执行这两个过程,我很难找到为什么从代码执行SPs会消失的原因。不是说没有一个:D只是我甚至猜不出为什么现在会发生这种情况。
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), tempTableName, startIndex, maxRowCount);