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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:16:02+00:00 2026-05-15T09:16:02+00:00

Here is my object association: Summary -> Job -> Operator -> Job -> Operator

  • 0

Here is my object association:

Summary
-> Job
  -> Operator
-> Job
  -> Operator

So, I have a Summary object that contains a collection of Jobs, which has an Operator object (clock #, name, etc)

When creating a new summary, I go through and create the new jobs that exist and add all the properties. Then, do a single insert on the Summary object that is built. Then, this inserts new jobs and operators if needed, otherwise I may read existing Jobs and Operators from the database.

The problem comes in when I have the same Operator running both Jobs and that Operator does not exist in the database. Linq-To-SQL is trying to insert the same object twice and failing since I’m using the clock # as the primary key.

I can create an auto number for the primary key, but then I’ll have duplilcate data and I’d rather not do that. Does anyone have any ideas to get around this?

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-15T09:16:03+00:00Added an answer on May 15, 2026 at 9:16 am

    I think the problem resides in how you write your object creation. I haven’t seen your code, but I think you’re doing something like this:

    Summary summary = new Summary
                                      {
                                          Jobs = new List<Job>
                                                     {
                                                         new Job
                                                             {
                                                                 Operator = new Operator {Name = "foo"}
                                                             },
                                                         new Job
                                                             {
                                                                 Operator = new Operator {Name = "foo"}
                                                             }
                                                     }
                                      };
    

    If that’s your case, try instantiating the operator “foo” beforehand and then assigning it to both jobs.

    If you already do it and still get the error, then you should create the operator before and save it to the database, then retrieve it and assign it to the desired jobs.

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

Sidebar

Related Questions

Here is the scenario: I have an object called a Transaction that needs to
I have an association with a condition that refers to a different object from
I have a Hibernate POJO with 1.an one-to-one association to another object 2.one-to-many association(collection)
I have seen the related question here: An object with the same key already
public void test(Object obj){ //Here i have to set the values of the obj
Here's a simplified example of an object I have. What I would like to
I'm trying to test a model that has an implicit has_many association, and am
I have a event model that has many invitations. Invitations are setup through checkboxes
I have a really simple association with the Devise user object where each user
I have seen the railscast on self-referential relationships here: http://railscasts.com/episodes/163-self-referential-association I have built upon

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.