I have a DbSet
property in my context class as follows:
public class ProjectContext: DbContext
{
public ProjectContext(): base("name=DBCS")
{
}
public DbSet<Employee> EmployeeDbSet { get; set; }
}
This property is being used in many places of my project. Now I need to set a generic condition on Employee
such as I need only active employees. I can get active employees by simply filtering my linq queries like this:
var employees = context.EmployeeDbSet.where(e => e.IsActive).ToList();
Since I've already written many queries in many places of my project, now I have to rewrite them all which is very difficult, time-consuming and error prone.
As this is a generic condition and I want to set this on all queries, I'm looking for a way to set the condition on EmployeeDbSet
property instead.
Can it be accomplished?