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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:24:52+00:00 2026-05-11T18:24:52+00:00

This has to be a frequent question, but not on SO yet, so it

  • 0

This has to be a frequent question, but not on SO yet, so it seems. I am using Linq to SQL for an application that allows a variety of data changes to my in-memory model, and the changes will then get placed into a queue for asynchonous processing. So, I am not worried about updates (yet).
Changes to various parts of the data can be made through modal popups on the web page. Some are grid-based, others are just attributes.
I am running into a problem with changes not surviving postback cycles. Obviously, I don’t want to persist anything to the database until all changes are made and the user submits the page.

The route that I have chosen so far is:

  • I disabled deferred loading
  • I create a [serializable] partial class for my root object
  • I put the thing into the session and retrieve it in the onload event

This seems to work in principle. However, when I try to update some of the children’s properties after retrieving the object from the session

p.PhysicianSpecialties[0].physician_specialty_code = 
    ddlSpecialty.SelectedItem.Value;

I get this error:

Operation is not valid due to the current state of the object.

The error is caused by this method call in the generated Linq setter method:

this.SendPropertyChanging();

Other properties get updated just fine:

p.PhysicianNames[0].first_name = txtFirstName.Text.ToUpper();

This does not cause an error.

My questions: Am I fundamentally on the wrong track? Is there a better way of doing this? What causes the error?

Update:
The exception is ‘System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException’. I think I am on to something, but I don’t know the solution yet.

  • 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-11T18:24:52+00:00Added an answer on May 11, 2026 at 6:24 pm

    I got the solution from MSDN. The issue is, and it is explained better in this thread than I can do it, that one cannot change an association unilaterally, but has to do it on both ends, by assigning a new child object, not just by a changing the id:

    p.PhysicianSpecialties[0].PhysicianSpecialtyLookup =
    db.PhysicianSpecialtyLookups.Single(c =>
    (c.physician_specialty_code == ddlSpecialty.SelectedItem.Value));

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

Sidebar

Related Questions

This has been a problem that I haven't been able to figure out for
This has got to be something I just missed, but how do I add
I have a method that has a parameter of type DateTime that must not
I am doing an application that will compute all 2 size frequent itemset from
This has been an adventure. I started with the looping duplicate query located in
This has been driving me crazy for a few days. Why doesn't the following
This has happened to me 3 times now, and I am wondering if anyone
This has been troubling me for a few years, and was recently exacerbated by
This has got to be something simple: I set up a frames page with
This has bugged me for a long time. 99% of the time, the GROUP

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.