我不知道是否有更好的方法来使用它,DbContext因为在使用WCF时不建议将其设置为静态.所以我们每次想要访问数据库时都会创建它.
了解使用实体框架的所有优点,有些变得无用,因为我们DbContext每次都在重新创建; 因为要考虑创建大实体模型的过程,所以可能会导致更多开销.
你有什么意见?
请检查以下代码部分(简化版)
我担心的是ReadPath我需要调用我正在使用的类型的GetPath()的类.我怎样才能做到这一点?
public interface IPath
{
string GetPath();
}
public class classA: IPath
{
string GetPath()
{
return "C:\";
}
}
public class classB: IPath
{
string GetPath()
{
return "D:\";
}
}
public class ReadPath<T> where T : IPath
{
public List<T> ReadType()
{
// How to call GetPath() associated with the context type.
}
}
Run Code Online (Sandbox Code Playgroud)