Rather simple question regarding entity framework and how to consume the objectcontext.
In a asp.net webform application I am implementing most of data getters in a data class and trying to determine if its better (in a generic sense of better) to have a private context for the entire class or declare a context in each of the methods.
Example 1:
public class Data
{
     private MyEntity context = new MyEntity();
     public Customer GetCustomer()
     {
        return context.Customer.Single();
     }
     public Order GetOrder()
     {
        return context.Order.Single();
     }
}
Or Example 2:
public class Data
{
     public Customer GetCustomer()
     {
        using (MyEntity ctx = new MyEntity()) 
        {
           return context.Customer.Single();
        }
     }
     public Order GetOrder()
     {
        using (MyEntity ctx = new MyEntity()) 
        {
           return context.Order.Single();
        }
     }
}
 
     
    