开发者

Is it necessary to restrict Entity Framework access by singleton?

Within the realm of Entity Framework, if I have 2 seperate classes leveraging a data model, do I need to ensure that there is only 1 reference to the entities object (singleton or similar)? In other words, in the scenario bel开发者_如何学JAVAow, is there any danger?

public class Foo
{
    public void DoSomething()
    {
        using (MyEntities entities = new MyEntities())
        {
            //use _entities in some fashion here
        }
    }
}

public class Bar
{
    public void DoSomething()
    {
        using (MyEntities entities = new MyEntities())
        {
            //use _entities in some fashion here
        }
    }
}

Thanks.


Here's a blog post which you might find interesting about lifetime of data contexts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜