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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:47:06+00:00 2026-06-04T11:47:06+00:00

Here is my question.I will try to make my question as simple as I

  • 0

Here is my question.I will try to make my question as simple as I can.. So, i have 2 classes and respectively two tables in a database which are not connected with each other, lets name them class A and class B wich look like:

public class User
{
[Key]
public int userID{ get; set; }

public User(string aName, string aPhone, string aEmail)
{
    Name = aName;
    Email= aEmail;
    Phone= aPhone;
}

public string Name { get; set; }
public string Email{ get; set; }
public string Phone{ get; set; }
}

public class Work
{
[Key]
public int workID{ get; set; }

public Work(string aWorkName, string aAddress, string sPosition)
{   
    WorkName= aWorkName;
    Address= aAddress;
    Position= aPosition;
}
public string WorkName{ get; set; }
public string Address{ get; set; }
public string Position{ get; set; }

}

what I want to do now is to create third class, and third table in the database.I should be able to fill the columns in the third table with the information from the previous two tables. For example its columns should be Name Phone Email WorkName Address Position.So I take the NameID and workID and based on these primary keys I should fill the third table with all the information.How should it be done?I think it should be done something like this:

public class CombinedTable
{
[Key]
public int cID{ get; set; }
public User user{ get; set; }
public Work work{ get; set; }
}

and lets say in the main function some query like this:

 var UserResult = from p in db.User
 where p.UserId.Equals(userID)
 select p;
 var WorkResult= from p in db.Work
 where p.WorkID.Equals(workID)
 select p;

var combinedInfo= new CombinedTable()
        {
            User = UserResult,
            Work= WorkResult
        };
        db.CombinedTable.Add(combinedInfo);
        int savedChanges = db.SaveChanges();

But I am missing something.I hope you get the idea..I am using entity framework and code first.Any suggestions wiil be very appreciated.Thank you. P.S. : Just to clarify it one more time.If I take workID=5 and UserID= 1, in the third tabe there whould be created new row from the Information for user with ID 1 and work with ID 5.Do you get it?I hope someone get it..

  • 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-04T11:47:08+00:00Added an answer on June 4, 2026 at 11:47 am

    Assuming you have a 1 to many relation between User and Work entities (One User can have many work)

    public class User
    {
      public int UserID { set;get;}
      public string Name { set;get;}
      public string Email{ set;get;}
      public virtual IEnumerable<Work> Works { set;get;}
    }
    
    public class Work
    {
      public int WorkID { set;get;}
      public string WorkName { set;get;}
      public string Hours { set;get;}
      public string Location { set;get;}
    }
    

    That will create the tables with 1 to many relationships and you should be able to query it easily like this

    int userId=34;
    var thatUser=dbContext.Users.Find(userId);
    var works=thatUser.Works;
    

    EDIT: If you want a third table, create a class for that

    public class UserWork
    {
      public int UserWorkID { set;get;}
      public int UserID { set;get}
      public int WorkID { set;get;} 
      public virtual User User { set;get;}
      public virtual Work Work  {set;get;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure how you'll take this question but... Whenever I try to make my
I will try to make this as straight forward as possible. This question does
I will try to make my question sound as unconfusing as possible. I appologize
I'll try to simplify and make clear my other question here. I am basically
I am going to try to make this question as clear as I can.
I may not have enough information to generate a complete question here but I
It might be a long shot posting this question here but we will see.
Here is a very and straight forward question: How long will it take to
Simple question here: is there any way to convert from a jagged array to
C# question here.. I have a UTF-8 string that is being interpreted by a

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.