Should EF DbContext contain all tables?

I'm new to EF4 and I'm trying to figure out how to create a DbContext class.

Is there any problem (especially high performance) when putting all my tables / entities in one and only one DbContext class, for example, the code below?

public class AllInOneDb : DbContext
{
    public DbSet<Customer> Customers{ get; set; }
    public DbSet<Address> Addresses{ get; set; }
    public DbSet<Order> Order{ get; set; }
    public DbSet<Product> Products{ get; set; }
    public DbSet<Category> Categories{ get; set; }
    // and more and more entities...
}

Or should I model my classes based on subsets of functionality?

public class CustomerDb : DbContext
{
    public DbSet<Customer> Customers{ get; set; }
    public DbSet<Address> Addresses{ get; set; }
    public DbSet<Order> Order{ get; set; }
}

public class ProductDb : DbContext
{
    public DbSet<Product> Products{ get; set; }
    public DbSet<Category> Categories{ get; set; }
    public DbSet<Order> Order{ get; set; } // look Order entity again!
}

thank

+5
source share
1 answer

, -, DbContext. ( , Driven Driven Design ). DbContexts, , . , . (, DbContext DbSet )

- . Entity Framework , , .

(Order) , Entity . DbContext DbContext. ( ) , .

Order order;
using (var custDb = new CustomerDb()){
   order = custDb.FirstOrDefault(o=>OrderId == "orderid");
}
using (var prodDB = new ProductDb()){
   prodDB.Attach(order);
   ...
}
+7

All Articles