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