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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:44:27+00:00 2026-05-14T00:44:27+00:00

I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile

  • 0

I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile there can be many teams.

So there’s a one-to-many relation on the driver_profile to team_data table. I want to update a team_data foreign key reference in the Driver_profile table of an already existing record to another team_data record that already exists.

I want to do this using entity framework. Here what I want: having a list of teams to select from, finding the record in the team_data table and updating it’s FK in the driver_profile appropriately.

So in the code below, the passed parameter is the newly selected team out of the team_data table.

Now I need it to update it FK reference in the Driver_profile table.

Here’s what I’ve got:

UPDATE: Code Updated. It does not save it to database, even if I call savechanges. No errors.

 public Driver_PROFILE_DATA GetSelectedTeam(string team)
    {
        ObjectQuery<Team_DATA> td = raceCtxt.Team_DATA;
        ObjectQuery<Driver_PROFILE_DATA> drpr = raceCtxt.Driver_PROFILE_DATA;

        var selteam = from t in td where t.Team_Name == team select t;

        Team_DATA newteam = new Team_DATA();

        newteam = selteam.Select(x => x).First();

        // get driver_profile with associated team_data
        var data = from a in raceCtxt.Driver_PROFILE_DATA.Include("Team_DATA") select a;
        // put it in driver_profile entity
        profileData = data.Select(x => x).First();

        profileData.Team_DATAReference.Attach(newteam);

        return profileData;
    }
  • 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-05-14T00:44:28+00:00Added an answer on May 14, 2026 at 12:44 am

    Entity Framework should give you a nice Association between the two classes, Update the references as you would using POCOs and stay away from the ID values.

    Something like:

    newTeam.Profile.Teams.Remove(profileData);  // separate from old Profile
    profileData.Teams.Add(newTeam);
    

    EDIT:

    I made a little test, it is sufficient to set the reference to the Parent object:

    newTeam.Profile = profileData;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in my MySQL database, one is a library of all
I have a many to many table setup in my mysql database. Teams can
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables: players (has a team name column) and teams (also has
I have two tables in APEX that are linked by their primary key. One
I have 2 database tables: Teams and Games. For the purpose of this question,
I have two Oracle SQL Tables: Team and Work. I want to select all
I have two database tables, Team ( ID, NAME, CITY, BOSS, TOTALPLAYER ) and
I have a fixtures and a teams database to show football fixtures. I can
I have two tables: teams ---------------- |uid|name |rank| ---------------- | 1 |Team1| 1 |

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.