小编Boo*_*mer的帖子

为什么在使用实体框架时重新启动DbContext?

我不知道是否有更好的方法来使用,DbContext因为在使用WCF时不建议将其设置为静态.所以我们每次想要访问数据库时都会创建它.

了解使用实体框架的所有优点,有些变得无用,因为我们DbContext每次都在重新创建; 因为要考虑创建大实体模型的过程,所以可能会导致更多开销.

你有什么意见?

.net c# wcf entity-framework-4 dbcontext

36
推荐指数
1
解决办法
2万
查看次数

通用中没有静态.但是如何实现这一目标呢?

请检查以下代码部分(简化版)

我担心的是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)

.net c# oop

0
推荐指数
1
解决办法
110
查看次数

标签 统计

.net ×2

c# ×2

dbcontext ×1

entity-framework-4 ×1

oop ×1

wcf ×1