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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:23:00+00:00 2026-06-08T08:23:00+00:00

I have a simple relationship: I have a Note object, which has a related

  • 0

I have a simple relationship:

I have a “Note” object, which has a related “Company” object.
When creating a “Note”, you select an existing “Company”, and enter the other neccessary fields.

My issue is that whenever I save, it inserts a new version of the “Company” object, and I can’t figure out why.

I have tried all the options in the accepted answer here Insert new object with existing object but nothing works.

Currently, I am doing the following:

var company = db.Company.FirstOrDefault(i => i.ID == note.Company.ID);
note.Company = company;

db.Notes.AddObject(note);
db.ObjectStateManager.ChangeObjectState(company, EntityState.Unchanged);
db.ObjectStateManager.ChangeObjectState(note, EntityState.Added);

db.SaveChanges();

But, it keeps adding a new “Company” object. What is strange, is that it doesn’t add all the fields, just the CompanyName” field, (and creates a new Id).

  • 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-08T08:23:03+00:00Added an answer on June 8, 2026 at 8:23 am

    If this is an existing company, set the CompantID field and not the entity

    note.CompanyID = company.ID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple one-to-many relationship. I would like to select rows from the
I'm creating a (theoretically) simple hasMany relationship within a domain class. I have two
I have a simple relationship. A campaign is linked to two Pages. A page
I have a simple has_one/belongs_to relationship between two models. This is a new association
I have a fairly simple foreign key relationship displayed by an inline in Django's
I'm getting started with FubuMVC and I have a simple Customer -> Order relationship
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple class with width and height member fields which define number of
I have a simple many to many relationship and I am wondering how you
I have a simple 1:many aggregate relationship, lets say: public class Parent { public

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.