【发布时间】:2012-01-18 16:43:50
【问题描述】:
我有一个以以下开头的通用类:
public class EntityContextFactory<T>
where T: class, IDisposable, IObjectContextAdapter, new()
稍后在课堂上,当我有一个包含以下内容的方法时:
T context = HttpContext.Current.Items[objectContextKey] as T;
if (context != null)
{
context.Dispose();
GC.SuppressFinalize(context);
HttpContext.Current.Items.Remove(objectContextKey);
}
我收到来自 ReSharper 的警告,说 GC.SuppressFinalize 是在没有析构函数的类型上调用的。如何消除此错误?我知道 Dbcontexts 确实有一个析构函数,因为当我非一般地编写这种类型的类时,我没有得到这样的错误。我尝试声明 T 实现与 Dbcontext 相同的接口,但这似乎不起作用......
【问题讨论】:
标签: asp.net-mvc entity-framework generics ef-code-first destructor