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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:21:28+00:00 2026-06-04T08:21:28+00:00

I have this classes: public class User { [Key] public Guid UserId { get;

  • 0

I have this classes:

public class User
{
    [Key]
    public Guid UserId { get; set; }
    public string Address { get; set; }
    public double Latitude { get; set; }
    public double Longitude { get; set; }
    public string Units { get; set; }
    public int Distance { get; set; }

    public List<Sport> Sports { get; set; }
}

public class Sport
{
    [Key]
    public int SportId { get; set; }        
    public string Name { get; set; }        

    public List<User> Users { get; set; }
}

So, these classes, with the foreign keys many to many, generates in the database a table like that: SportUsers (SportId, UserId)

When a User, sign up, select from a listbox of Sports, the Sports in which he is interested. So in the Register action in the appropiate controller, I save the user like that:

db.Users.Add(user);
db.SaveChanges();

But, how can I save the list of sports in which the user is interested, in the autogenerated for the foreign key, SportUsers table ???

  • 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-04T08:21:31+00:00Added an answer on June 4, 2026 at 8:21 am

    If your User has a collection of Sports, Entity Framework will figure out that that’s a M*N relationship and automatically fill the relationship in your database.

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

Sidebar

Related Questions

Consider I have the following classes: class User { [Key] public Guid Id {get;
I have the following two classes: public class User { public Integer userId; //
I have this 2 classes: @Entity public class Student extends User { ... @ManyToMany(mappedBy
I have this structure of classes: public class L3Message { public int Number {
my code is like this: i have two classes first class: public class Box<E>
I currently have service classes that look something like this public class UserService :
I have classes structured like this: Public MustInherit Class A ' several properties End
If I have this classes: public interface IBinaryCalculator{ double addition(double numb1, double numb2); }
Say i have the following two classes: public class User { public int ID
So I have this two classes: public class PhysicalTest { public int ID {

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.