Search code examples
c#.netdesign-patternsc#-4.0fluent-interface

How to write generic innerJoin in Generic Repository?


i am using generic repository to develop my own BLL with entity framework.Generic Repository But all generic repository doesn't have inner join. Lokk below :

 public interface IRepository
{
    IQueryable<T> List<T>() where T : class;
    T Get<T>(int id) where T : class;
    void Create<T>(T entityTOCreate) where T : class;
    void Edit<T>(T entityToEdit) where T : class;
    void Delete<T>(T entityToDelete) where T : class;
}

How to convert above code to :

 public interface IRepository
{
    IQueryable<T> List<T>() where T : class;
    T Get<T>(int id) where T : class;
    void Create<T>(T entityTOCreate) where T : class;
    void Edit<T>(T entityToEdit) where T : class;
    void Delete<T>(T entityToDelete) where T : class;
void InnerJoin<T>(T entityName, TNew entityName2) where T : class, where TNew : class;
}

or i think that we can use Fluent interfacve pattern like that:

    public List<MyWorker> ListByID( int ID)
{
    using (var Ctx = new DomainRepository<Worker>(new ProposalsEntities()))
         return Ctx.Find<Worker>(q => q.ID== ID).ToList().InnerJoin(XEntity,x=>x.ID=q.ID).InnerJoin(YEntity,y=>y.ID=q.ID);
}

Yuo can give another advise to achive this fantastical question. How can i write above join code in Generic Repository?


Solution

  • A repository shouldn't expose join functionality. The domain object that the repository provides might be composed of data that's persisted in multiple tables but the domain layer shouldn't be aware of that fact or, more generally, of the format the data takes in the persistence layer. Some data sources may not even be able to provide join functionality.