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

  • SEARCH
  • Home
  • 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 7661307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:34:50+00:00 2026-05-31T13:34:50+00:00

I have two different views to the same database table and I would like

  • 0

I have two different views to the same database table and I would like to use same query against both views.

I have now following ugly solution where I have basically copy of the query.

DbSet<uvw_MyView1> view1 = entities.uvw_MyView1;
DbSet<uvw_MyView2> view2 = entities.uvw_MyView2;

if(doQueryOnView1)
{
    // huge query
    view1.Where(jada jada)
}
else
{
    // huge query copied here with exception of different DbSet
    view2.Where(jada jada)
}

What I would like to have is more elegant solution. Basically I want to have same query part for two DbSet’s that are in column wise exactly same, but those return different rows. Any ideas?

  • 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-05-31T13:34:51+00:00Added an answer on May 31, 2026 at 1:34 pm

    Add interface containing all properties of your view and implement this interface by both view entities. After that create method containing whole your query:

    public static IQueryable<T> YourHugeQueryMethod<T>(DbContext context, ...) 
         where T : class, IView, new()
    {
        DbSet<T> set = context.Set<T>();
        return set.Where(...);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different tables, lead and click. I would like to query MySQL
Is it possible that two different views use the same controller? I have very
In two different views I have the following two pieces of code. FIRST <table
I have a UITabBarController with two different views to switch between. What I would
I've got a table recording views of programs. Each program can have two different
I have two ViewModels that present the same Model to different Views. One presents
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I have two different grid controls on the same form. They share the same
I have an application that needs to query two different DB2 databases for the
I have two different views that makes upwards of 500 partial view calls each

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.