1

在實體框架中,我實現了通用資源庫和工作單元模式。在存儲過程中使用EF並出錯,因爲不允許新的事務,因爲會話中還有其他線程正在運行

下面是從工作單位相關的東西:

public IRepository<TEntity, TKey> GetRepository<TEntity, TKey>() where TEntity : class 
    { 
     if (_repositories == null) 
     { 
      _repositories = new Dictionary<string, object>(); 
     } 

     string key = String.Format("{0}|{1}", typeof(TEntity).Name, typeof(TKey).Name); 

     if (_repositories.ContainsKey(key)) 
     { 
      return (IRepository<TEntity, TKey>)_repositories[key]; 
     } 

     Type repositoryType = typeof(Repository<TEntity, TKey>); 
     _repositories.Add(key, Activator.CreateInstance(repositoryType, _dataContext)); 

     return (IRepository<TEntity, TKey>)_repositories[key]; 
    } 

從經理層,實體框架是調用如下:

 IRepository<tablenameEntity int> _tableEntityRepository = _unitOfWork.GetRepository<tablenameEntity, int>(); 

錯誤是如下:

An error occurred while starting a transaction on the provider connection. See the inner exception for details.

{"New transaction is not allowed because there are other threads running in the session."}.

回答

0

其實,我只是做了如下,

刪除存儲過程和模型瀏覽器功能再次並添加過程和函數。

在edmx文件上運行自定義工具。

它只是工作。

我不確定,問題是什麼。之前也是這樣做的,但這不起作用..現在,它起作用了,之後不會生產。

謝謝

+1

您可以通過選擇「打勾」來「接受」自己的答案。這將其從未解決問題的隊列中移除。 – 2015-06-02 09:54:53

相關問題