Are we using the repository pattern right?

We are using a bunch of separate classes suffixed with -repository to retrieve the data from the database; for each table its own repository.

We have for instance a customerrepository class which has all kind of methods to retrieve customers, and a vacancyrepository which has all kind of methods to retrieve vacancies.

I have two questions about this way of doing things:

  1. How about getting data which spans multiple tables? For instance I have a screen which shows all customers who have not yet created a vacancy. Can a customerrepository use methods from the vacancyrespository, or do both repositories return results and is there a class higher in the hierarchy (let’s name it a dataservice) which gets the results from both repositories and combine them into 1 result?

  2. how much logic can such a repository handle?
    I think it’s OK to implement the ‘where active == true’ in a repository to retrieve only active records, or should even that simple logic be handled by a class higher in the hierarchy (let’s name it a dataservice)?

The example I was running into now is this one:

We have a questions list, which contains one or more questions.
The question can have a result, which is hold in a separate table.
So when you want to retrieve the total result of the questions list, you have to combine data from the questionlist table, the question table and the questionstatus table.

Right now we have 3 different repositories for these tables.

If I would ask the questionlistrepository what it’s the total result for list number 12, it would have to get data from two other repositories and hence have some logic in it, is that allowed?

Or is there a questionlistdataservice which knows which repositories to use?

One more thing: our repositories can result an IQueryable so a calling service can easily combine the results, but how about when this isn’t the case, I don’t think it’s a good idea to retrieve all the content of all three tables from the database.

1

Repository returns domain objects and is built on top of mapping layers. For a very simple domain domain objects and database tables can be very much the same.

If your repository is always returning exact representation of your data structure then it might actually be Table Data Gateway aka Data Access Object(DAO).

Example:
Your database has tables for person and address. In your application domain address is not an entity of it’s own, it is just a property of Person. In this case you would not have PersonRepository and AddressRepository. You just have PersonRepository. Domain should not be concerned how the domain data is persisted. Those responsibilites are in a layer behind repository.

From your example it would seem you actually have DAOs and have just named them Repositories.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật