gpt4 book ai didi

c# - 创建模型时无法使用上下文异常

转载 作者:太空宇宙 更新时间:2023-11-03 15:32:09 25 4
gpt4 key购买 nike

<分区>

我在使用 Entity Framework 6.0.0.0 时遇到以下错误。

The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the
OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe. It is fired inside an async method ,upd:

   public async Task<IList<Model>> GetEntities(filter f)
{
using (var db = new MyDbContext())
{
var query = db.MyDbSet.AsQueryable();

if (f != null && f.field.Any())
//Exception throwed here
query = query.Where(a => f.field.Contains(a.field));

return await query.ToListAsync();
}
}

但是,当我尝试通过 Where 子句查找我的实体时,不会执行任何 await 调用或其他多线程操作。

关于这个问题有什么建议吗?我找到了很多答案,但没有发现它们对我有帮助。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com