KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am creating a new project using business objects (Employee, Product). Due to constraints, I am not using LINQ to SQL or any ORM Mapper. I have to hand code the Data Access Layer(s). I am interested in using the 'Repository Pattern'. According to what I understand, I have to create a generic repository IRepository which is implemented by all repositories ProductRepository, EmployeeRepository . What confuses me is that different business objects have different requirements. For example: ProductRepository GetAllProducts (); GetProductById (int id); GetProductByMaxPrice (double price); GetProductByNamePrice (string name, double Price); Get... (...); EmployeeRepository GetEmployeeByAge (); GetEmployeeByJob (string description); GetEmployeeBySalary (double salary); Get... (...); //and so on How can I create a generic repository which meets different data access requirements of different objects ? I have read a lot of theory regarding Repository Pattern but would really appreciate a working example. Additionally, if I can create all repositories using a generic repository, using the factory pattern becomes easy aswell. For example: interface IRepository { .... } ProductRepository : IRepository { .... } EmployeeRepository : IRepository { .... } Then we can use the factory pattern effectively as: IRepository repository; repository = new ProductRepository (); repository.Call_Product_Methods (); repository = new EmployeeRepository (); repository.Call_Employee_Methods ();
Tags (comma-separated)
Save Edits
Cancel