Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:00:40+00:00 2026-06-18T03:00:40+00:00

Using the Code First approach I have created a number of different entities that

  • 0

Using the Code First approach I have created a number of different entities that inherit from an interface IConcurrent with a property IsActive for example:

public class Currency : IConcurrent
{
    public string CurrencyId { get; set; }

    public string Description { get; set; }

    public bool IsActive { get; set; }
}

Each time I select entities I find myself always having to include a conditional clause such as this real basic example:

db.Currencies.Where(c => c.IsActive);

My question is that is it possible to some how intercept/hook into the DbContext so that my LINQ queries will always return IsActive == true for entities that inherit the IConcurrent interface, to avoid having to explicitly add .Where(c => c.IsActive) each time?

So far I’ve looked at the possible methods to override in DbContext which none of them seem to fit the bill. Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:00:42+00:00Added an answer on June 18, 2026 at 3:00 am

    You can use filtering on the Set<> method to get just active instances, something along the lines of:

    public IQueryable<T> GetActive<T>() where T : class, IConcurrent
    {
       return Set<T>().Where(e => e.IsActive);
    }
    

    This method could be included in a class that inherits the DbContext class, or you could make it into an extension method, like:

    public static DbContextExtensions
    {
      public static IQueryable<T> GetActive<T>(this DbContext context) 
        where T : class, IConcurrent
      {
         return context.Set<T>().Where(e => e.IsActive);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table created using Entity Framework Code First approach. How do
I'm using the Code First approach and have the following Model: public class Person
We are using EF 4.0 with code first approach. I have defined constraint for
I'm using Code First with EF 5. Currently I have SPs that return just
I'm using Entity Framework 5, and a code first approach. I have a Product
I have following C# code that uses Entity Framework Code First approach. The tables
I'm using the Code First approach to build the database in this problem. I
I successfully created database on my local server using Code First, migrated it to
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First
I have a generic repository implementation. I'm using asp.net mvc c#, code first entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.