var j = db.jobs.Where(x => x.Title.Contains(keyone)).ToList();
i want to implement this using generic repository but i can't figure out how to do it.using generic repo
var j = db.jobs.Where(x => x.Title.Contains(keyone)).ToList();
i want to implement this using generic repository but i can't figure out how to do it.using generic repo
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sophia CarterRank #4,018 · 371 reputationPosted Mar 13, 2025, 7:45 AM EDT
Of course! Implementing the functionality you mentioned using a generic repository is a great approach for maintaining a clean and scalable data access layer in your application.
To achieve this using a generic repository pattern, you can follow these steps:
1. Define a Generic Repository Interface:
Create a generic repository interface that includes common CRUD (Create, Read, Update, Delete) operations like GetById, GetAll, Add, Update, Delete, etc.
public interface IRepository { TEntity GetById(int id); IEnumerable GetAll(); void Add(TEntity entity); void Update(TEntity entity); void Delete(TEntity entity); // Add more specific methods as needed }2. Implement the Generic Repository:
Create a concrete implementation of the generic repository interface. This implementation will interact with your database context.
public class Repository : IRepository where TEntity : class { private readonly DbContext _context; public Repository(DbContext context) { _context = context; } public TEntity GetById(int id) { return _context.Set().Find(id); } public IEnumerable GetAll() { return _context.Set().ToList(); } public void Add(TEntity entity) { _context.Set().Add(entity); } public void Update(TEntity entity) { _context.Set().Update(entity); } public void Delete(TEntity entity) { _context.Set().Remove(entity); } // Implement other methods if needed }3. Use the Generic Repository in Your Application:
You can now use the generic repository in your application to perform operations like filtering by the job title containing a specific keyword.
var jobsContainingKeyword = repository.GetAll().Where(x => x.Title.Contains(keyone)).ToList();By following the above steps, you can implement a generic repository pattern that allows you to abstract data access operations and easily extend the functionality in the future. This approach promotes reusability and maintainability in your codebase.
umair mohsinRank #3,092 · 463 reputationPosted Mar 13, 2025, 7:50 AM EDT
i have tried this and results are good but i want to to do like this
IEnumerable Search(Expression> where, Expression> select);
its the interface fuction definition and needs to be implemented but using this results are not good
Sangeetha SRank #212 · 11.4K reputationPosted Mar 13, 2025, 9:24 AM EDT
Findmethod for filtering.Jobentity andApplicationDbContext.JobService) to use the repository for querying jobs by title.