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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:39:07+00:00 2026-06-01T18:39:07+00:00

In my scenario I have a many to many relationship with single table. So

  • 0

enter image description here
In my scenario I have a many to many relationship with single table.
So in Player_VsMode I have two foreign keys of Player table. One is for Player and second for Opponent. When I am trying to insert in the table Player_VsMode. Insertion of data in Player_vsMode is all fine but in Player it adds a new row of opponent Object. And this is not making sense to me why the Hell EntityFramework adding this new row of Opponent! My code is

 public Void performVsMode(Player_VsMode vsMode)
    {
        Player playerFromDB = legendWarsEntities.Player.First(v => v.email == vsMode.Player.email);
        Player enemyFromDB = legendWarsEntities.Player.First(v => v.email == vsMode.Opponent.email);
        vsMode.PlayerReference.Value = playerFromDB;
        vsMode.OpponentReference.Value = enemyFromDB;
        legendWarsEntities.AddToPlayer_VsMode(vsMode);
        legendWarsEntities.SaveChanges();

    }
  • 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-01T18:39:08+00:00Added an answer on June 1, 2026 at 6:39 pm

    I DO NOT RECOMMEND THIS
    Just did a work around to say to Project Manager that it’s Working :).

      Player playerFromDB = legendWarsEntities.Player.First(v => v.email == vsMode.Player.email);
            Player enemyFromDB = legendWarsEntities.Player.First(v => v.email == vsMode.Opponent.email);
            vsMode.PlayerReference.Value = playerFromDB;
            vsMode.OpponentReference.Value = enemyFromDB;
            //adding records
            legendWarsEntities.SaveChanges();
            //deleting extra Opponent Object!!!
            Player[] playerToDel = legendWarsEntities.Player.Where(v => v.email == vsMode.Opponent.email).ToArray();
            legendWarsEntities.DeleteObject(playerToDel[1]);
            legendWarsEntities.SaveChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the scenario: You have a Persons table with a one-to-many relationship with
Imagine the following scenario: I have two classes in a one-to-many relationship and I
Let's say I have two tables with a one-to-many relationship. I want to create
I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.
I have two distinct scenarios. One, where there is a many to many case,
Scenario I have 3 database tables. One is for Images and the other two
I have the following scenario. I have one table in the database A that
I have two tables that share a one to one relationship (in truth its
I have a scenario where I need to search from many binary files (using
I have used Dictionary(TKey, TValue) for many purposes. But I haven't encountered any scenario

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.