TdsParserStateObject - 处理?实体框架

ada*_*o94 6 c# entity-framework

我正在使用EF而且有问题TdsParserStateObject.

我多次调用这个方法:

 public void SaveDataFromERP(string synchronizationType, string xml,int errorsHandlingPercentagePartition)
    {
        var param1 = new SqlParameter("XML", SqlDbType.Xml);
        param1.Value = xml;
        var param2 = new SqlParameter("PartitionedPackagePercentage", SqlDbType.Int);
        param2.Value = errorsHandlingPercentagePartition;
        ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<dynamic>(
            $"exec [Synchronization].[Import{synchronizationType}] @XML,  @PartitionedPackagePercentage", param1 , param2 );
}
Run Code Online (Sandbox Code Playgroud)

我的存储库包括

SynchronizationRepository : ISynchronizationRepository
{
  private readonly POSDBContext _context = new POSDBContext();
  public void SaveData(string typeName, string xmlFile, int errorsHandlingPartitionPercentage)
    {
        _context.SaveData(typeName, xmlFile,errorsHandlingPartitionPercentage);
    }
 }
Run Code Online (Sandbox Code Playgroud)

当我打电话时,ExecuteStoreQuery我可以在内存中看到新对象TdsParserStateObject.

不幸的是,我必须多次按顺序调用此方法(大量数据).结果是大约60 TdsParserStateObject,它需要大量的内存.

而且这些物体在一段时间后不会消失.

可以处理它们吗?

在此输入图像描述

小智 1

通过删除以下内容在某种程度上解决了我自己的问题:

"MultipleActiveResultSets=True"

来自我的连接字符串。我的连接是在后台线程上建立的,因此这在某种程度上解释了为什么我看到了增长:

https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets