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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:41:51+00:00 2026-06-04T13:41:51+00:00

I have problem with saving many to many relationship. When I run the code,

  • 0

I have problem with saving many to many relationship.
When I run the code, my mapping table “dbo.UserTown” does not have any data saved in this any idea why?

I have wrote my function for saving the users with lists of towns

  public void Save(User user)
    {
        context.User.Add(user);
        context.SaveChanges();
    }

My classes are like this:

public class User
{
    public long UserId { get; set; }
    public String Nickname { get; set; }
    [InverseProperty("Residents")]
    public virtual ICollection<Town> Residencies { get; set; }
}

and

public class Town
{
    public long TownId { get; set; }
    public String Name { get; set; }
    public virtual ICollection<User> Residents { get; set; }
}
  • 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-04T13:41:52+00:00Added an answer on June 4, 2026 at 1:41 pm

    Stange but i have discovered next day:
    I have done steps to clear problem:

    1. Fresh mug of coffe 🙂
    2. cleared all cashe in vs (clear all projects), Closed Visual Studio for sure
    3. Removed database
    4. Open VS and run project => this step created database
    5. Important: did NOT changed my code
    6. Run the project 2nd time to seed dummy data into system
    7. My table is populated.

    Real headscratcher…

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

Sidebar

Related Questions

I seem to have a problem with my meta box saving, not totally sure
Hi I have a problem saving 2 tables of my database at the same
I am using CakePHP framework with MySQL database and I have problem in saving
I have this problem with saving a date into a MySQL database. I have
i have problem to pass data from view to controller , i have view
I have an NSManagedObject that has a to-many relationship to another NSManagedObject. During creation
I have a many-to-many relationship: Application -> Applications_Servers -> Server This is set up
I have two related objects: ProgramSession and ProgramTask, with a one-to-many relationship. A ProgramSession
I'm currently facing in problem using Core Data. I have two entities A and
I have a one-to-many relationship within my class model. Example: A single role can

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.