我有以下代码:
现在这个正在运行,但是我遇到了错误:
阅读后,看起来
那么如何转换此查询的结果呢?因为我尝试使用
下面是代码:
public Task<Service> GetSomething()
{
using (var myContext = new DbContext())
{
var returnObj = (from rp in myContext.Services1
join op in myContext.Services2 on rp .Id equals op.ServiceId into g
join ep in myContext.Services3 on rp .Id equals ep.ServiceId
from n in g.DefaultIfEmpty()
where rp.Name == code
select rp).FirstOrDefaultAsync();
return returnObj;
}
}
现在这个正在运行,但是我遇到了错误:
The operation cannot be completed because the DbContext has been disposed.
阅读后,看起来
FirstOrDefaultAsync
是延迟执行的,我需要先将其转换为 list
。那么如何转换此查询的结果呢?因为我尝试使用
.ToListAsync()
,但它不再有任何 FirstOrDefault
。