开发者

Is it necessary to restrict Entity Framework access by singleton?

开发者 https://www.devze.com 2023-01-27 13:31 出处:网络
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 w

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

精彩评论

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

关注公众号