Witam
Piszę sobie aplikacje korzystająca z ORM(EF), głównie wzoruje się na książce ASP.NET MVC 3. Tam autor używa dla każdej tabeli repozytorium.
Np.
public interface IProductRepository
{
IQueryable<Product> Products { get; }
}
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IQueryable<Product> Products { get { return context.Products; } }
}
class EFDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
}
I tak to wygląda dla każdej tabeli, ale oczywiście w książce nie ma nic jak sobie radzić kiedy potrzeba stosować złączenia. Trochę uciążliwe było by tworzenie nowego repo dla dwóch tabel aby wykonać zapytanie ze złączeniem. Więc z tego powodu chce wrzucić całą bazę danych do jednego repo, ale czy takie coś ma w ogóle sens?
class EFDbContext : DbContext
{
public DbSet<Network> Networks { get; set; }
public DbSet<Algorithm> Algorithms { get; set; }
public DbSet<Collection> Collections { get; set; }
public DbSet<Set> Sets { get; set; }
public DbSet<Input> Inputs { get; set; }
public DbSet<Output> Outputs { get; set; }
}
interface ILynxRepository
{
EFDbContext Context { get; }
IQueryable<Algorithm> Algolithms { get; }
IQueryable<Network> Networks { get; }
IQueryable<Collection> Collections { get; }
IQueryable<Set> Sets { get; }
IQueryable<Input> Inputs { get; }
IQueryable<Output> Outputs { get; }
}
class EFLynxRepository : ILynxRepository
{
EFDbContext context = new EFDbContext();
public EFDbContext Context { get { return context; } }
public IQueryable<Algorithm> Algolithms { get { return context.Algorithms; } }
public IQueryable<Network> Networks { get { return context.Networks; } }
public IQueryable<Collection> Collections { get { return context.Collections; } }
public IQueryable<Set> Sets { get { return context.Sets; } }
public IQueryable<Input> Inputs { get { return context.Inputs } }
public IQueryable<Output> Outputs { get { return context.Outputs; } }
}