How should I extend a generic repository

asp.net-core c# entity-framework-core repository-pattern

Question

Trying to understand if I can extend a Generic Repository Interface or not.

Sorry, I'm new to this and have google search this and can't find any such implementation which leads me to think I'm trying to defy the generic repository logic.

I'm using EF Core ORM.

I have IRepository<T>:

IEnumerable<T> GetAll();
T Get(long id);
void Insert(T entity);       
void Update(T entity);
void Delete(T entity);

I then implement a Generic Repository:

public class Repository<T> : IRepository<T> where T : class

However I need to implement a special method for ONLY one entity name Conference such as:

IList<T> GetIncludedItems(Expression<Func<T, bool>> predicate, params string[] navigationProperties);

How can I extend my Generic Repository to handle that one exception method without having the other entities implementing it. In addition, my service class will be implementing these Repositories via constructor injection.

public ConferenceService(IRepository<Conference> _conferenceRepository )

I also need to maintain Dependency binding via my ConfigurServices.

services.AddScoped<IConferenceService, ConferenceService>();

Any suggestion where I'm going wrong or how I can accomplish this?

1
-1
8/18/2017 2:48:13 PM

Accepted Answer

Here is the solution to my problem, I need to inherit the base repository if I want to add a custom method for a specific entity. click here to see how to solve the above problem

0
8/18/2017 6:31:34 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow