我正在使用此库https://github.com/ziyasal/RepositoryT.EntityFramework
使用工作单元模式对dbContext
使用分层生命周期管理器时,在进行负载测试时会出现以下错误。如果我使用transientLifeTimeManager
,则负载测试通过,但我不能在表之间进行连接。对于表连接,我得到指定的LINQ表达式,其中包含对与不同上下文关联的查询的引用。
我正在等待所有查询
container.RegisterType<IDataContextFactory<MyDataContext>, DefaultDataContextFactory<MyDataContext>>(new HierarchicalLifetimeManager());
由于分层
导致的错误在上一次异步操作完成之前,在此上下文中启动了第二个操作。使用'await'确保在此上下文上调用另一个方法之前已完成任何异步操作。不保证任何实例成员都是线程安全的。
当我加入这样的事情时,它错误地用
from appLocale in _applicationLocalesRepository.GetAll()
join app in _applicationsRepository.GetAll()
on appLocale.ApplicationID equals app.ApplicationID
select appLocale).ToList()).Select(x => x.Locale)
我也曾尝试使用此功能
public class PerRequestLifetimeManager : LifetimeManager
{
private Guid key;
public PerRequestLifetimeManager()
{
key = Guid.NewGuid();
}
public override object GetValue()
{
if (HttpContext.Current == null)
{
return null;
}
else
{
return HttpContext.Current.Items[key];
}
}
public override void RemoveValue()
{
if (HttpContext.Current != null)
{
HttpContext.Current.Items.Remove(key);
}
}
public override void SetValue(object newValue)
{
if (HttpContext.Current != null)
{
HttpContext.Current.Items.Add(key, newValue);
}
}
}