I am implementing a generic repository pattern. I have done this quite a few times now but every time I do it there is something bugging me.
If I have a database design like below. (All the tables relate to one another.) And I make a call like the following:
public IEnumerable<Domain> GetRealEstate()
{
return _repository.GetAll();
}
I can get all the models from just that one call (The wonders of EF). The thing that bugs me is the fact that I have to say Domain
in the method call, from the domain entity I will get all the relevant entity (Lazy loading
) Companies
etc. etc. It just feels wrong to use domain entity to get all the companies etc. etc. The repo pattern that I am using is a straight forward one.
Is there a better way of writing the methods so that it does not look so weird?
Controller RealEstateController
[RoutePrefix("api/realestate")]
public class RealEstateController : ApiController
{
private readonly IRealEstateService _service;
public RealEstateController(IRealEstateService service)
{
_service = service;
}
[Route("")]
public Task<Domain> GetRealEstates()
{
var collection = _service.GetRealEstate();
return null;
}
[Route("{domainName}")]
public Task<Domain> GetRealEstate(string domainName)
{
}
}
Service
public class RealEstateService : IRealEstateService
{
private readonly IRealEstateRepository _repository;
public RealEstateService(IRealEstateRepository repository)
{
_repository = repository;
}
public IEnumerable<Domain> GetRealEstate()
{
return _repository.GetAll();
}
}