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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:44:57+00:00 2026-06-01T15:44:57+00:00

I want to get data from two tables with single Entity class. How?? public

  • 0

I want to get data from two tables with single Entity class. How??

public class HomeViewModel  
{ 
    [Key] 
    [Column("candidate_ID")] 
    public int candidateID { get; set; } 
    [Column("first_name")] 
    public string firstName { get; set; } 
    [Column("last_name")] 
    public string lastName { get; set; } 

    public string emailID { get; set; } 
    public string mb_country_code { get; set; } 
    public int mobile_no { get; set; } 
}

Above entity class holds 6 property where 3 property represents one table1 and 3 represents table2.
At database table 1 holds candidate_id as primary key and table two holds candidate_id as foreign key

Update: What i did is added DBContext class

public class EmployeeMonitoring : DbContext
{
    public DbSet<HomeViewModel> homeViewModel { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<HomeViewModel>().Map(m =>
            {
                m.Properties(a => new { a.candidateID, a.firstName, a.lastName,a.status });
                m.ToTable("table1");
            }).Map(m =>
            {
                m.Properties(c => new { c.candidateID,c.emailID, c.mobile_no, c.mb_country_code });
                m.ToTable("table2");
        });
     }
}`

and at Controller Action i used following Linq to Entity Query

var data = db.homeViewModel.ToList();

But it returns nothing, i.e 0 count.

  • 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-01T15:44:58+00:00Added an answer on June 1, 2026 at 3:44 pm

    Check data in daatbase table first.

    It is because you might not have related data in table2. i.e table1 primary key value (which is candidate_id) is not present in table2 foreign key candidateID…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get data from two tables. I have patient first name and
What I want to do is get the data from two different tables (table1
I want to get data from two tables in my database. Here's what my
I want to join two tables to get data from both tables, for example,
I am trying to get data from two related tables in a single query.
Is it possible to get data from two exactly the same tables and print
I'm trying to get data from two tables. Todo_Lists and Todo_Items. I manged to
I have two tables that I want to fetch data from. Lets call them
I want to get data from a table in my MySQL database. $linkID =
Whenever I want to get data from a plist file I use the following

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.