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 7750927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:25:04+00:00 2026-06-01T11:25:04+00:00

I need to do two/three independent queries and load into the same viewmodel and

  • 0

I need to do two/three independent queries and load into the same viewmodel and pass it to the view.

here is what I am doing, but it doesnt even compile, please take a look and let me know what I am doing wrong.. Thanks

UserViewModel class has 2 parameters, title, option

e.g.

UserViewModel user= new UserViewModel ();

    var model = (from a in db.Table1
     where string.Equals(a.username, "bob")
    select user
    {   user.Title = a.Title,
        user.option = 1
    });

Second query

    model = (from b in db.Table2
             where string.Equals(b.username, "bob")
             select user
             {
                 user.Title= b.Title,
                 user.option= 2
             });

var list = model.ToList();
return View("List",list);

This is simple queries and I know I can now put them into 1 query, but in the future It will be completely independent and I need to know how to do two/three queries and put them into one viewmodel. thanks

  • 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-01T11:25:05+00:00Added an answer on June 1, 2026 at 11:25 am
    var user = db.Table1
         .Where(m => m.username == "bob")
         .Select(x => new UserViewModel 
             {
                Title = x.Title,
                Option = 1
             })
          .Union(
               db.Table2
          .Where(m => m.username == "bob")
          .Select(x => new UserViewModel
            {
               Title = x.Title,
               option = 2
            })
          ).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following three arrays and need to create a new two-dimensional array
I am creating two independent C++ .dlls that both talk to the same piece
I've got a project that consists of two processes and I need to pass
what I need: - there are two images: a background (large) and a proifile
I need to merge two SELECT statements. There are two tables in my database,
There are two scenarios I need to clarify: An executable compiled with .NET 3.5
I need to join two JPA entities on a property when there is no
I need a library to handle JSON objects in Ruby. There are two gems
I need to solve such a problem. There is a base class and two
I have two numbers, and need to get returned the lower one. Is there

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.