![](/img/trans.png)
[英]Is the DbContext disposed when I do a ToList() in EF Core
[英]How can I read the non public member "_disposed" from EF CORE DbContext
我想检查 ef 核心上下文是否已处理。
我试过了:
context.GetType().GetMembers(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
context.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
context.GetType().GetProperties(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
不列出财产。
我不知道为什么有人可能需要它,但你可以这样做:
public class AppContext : DbContext
{
public override void Dispose()
{
IsDisposed = true;
base.Dispose();
}
public bool IsDisposed { get; private set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.