private void GetData(Candidate c)//for candidate index page
{
c.Alerts = db.Alerts.Where(a => a.CanId == c.CanId).ToList();
c.Bookmarks = db.SavedJobs.Where(sv => sv.CanId == c.CanId).ToList();
c.Applications = db.Applications.Where(app => app.CanId == c.CanId).ToList();
}
alerts, bookmarks,applications all are list from different tables i am fetching records from them using CanId
is there any way to do this task using generic repository( i just pass candidate in generic repo and all three list wrt id would return to me) or what is the long query to fill above lists with appropriate data.
what is the most suitable way to fill canditae model and pass it to view in terms of best practices
Tuhin PaulPosted Mar 9, 2024, 8:26 PM
Instead of using reflection to access the property named "CanId", let's assume that all entities have a property named "CandidateId". This simplifies the code and makes it more maintainable.
Jithu ThomasPosted Feb 22, 2024, 5:47 AM
Yes, you can achieve this using a generic repository pattern.
Make sure to adjust the code based on your actual entity types and context. This is a generic example to give you an idea of how to structure your repository pattern. The idea is to create a generic repository interface and class to handle common CRUD operations, and then inject those repositories into your service or controller.
In terms of best practices, it's a good idea to follow the SOLID principles, separate concerns, and keep your code modular and testable. Using a repository pattern can help with data access abstraction and testing.