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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:58:05+00:00 2026-05-23T01:58:05+00:00

I have a Answer table which has pk_answerid, answertext , fk_questionid, chosenoptions stored as

  • 0

I have a Answer table which has pk_answerid, answertext , fk_questionid, chosenoptions stored as 1,3,2 (comma separated)

answertext if populated, then chosenoptions null and if chosenoptions if populated then answertext is null.

ChosenOption table has structure pk_chosenoptionid, fk_questionid
In EntityFramework 4,
I have something along these lines

void SaveAnswers(ICollection<Answer> answers)
{
        context.Answers.Add(answers);
        context.SaveChanges();
}

This works fine….but when in the UI I go back to page which is wizard with Q&A’s on different pages and I deselect all answers previously selected, and click save, no answers are deleted. I also tried DeleteObject which does not delete the Answers and chosenoptions even though I have cascade delete on the Answer table to Chosen option table.
Also in edit scenarios if for e.g. if the User selected option 1,2 and then saves it and then goes back and selects 3,2 how do you write code in EF to do such complex stuff. I haven’t come across any tutorials which explain such scenarios. Most of what I have seen is simple add, delete and applypropertychanges. I have an MVC app, which has lazy loading enabled.
Pls help and suggest some sort of code using an example or any pointers to existing blogs where this is explained.

  • 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-23T01:58:06+00:00Added an answer on May 23, 2026 at 1:58 am

    EF doesn’t take care – I shame to posting this again and again but I really don’t like to explain it every time: Update relationships when saving changes of EF4 POCO objects

    Check that explanation. Your problem is similar. You persisted entity graph (set of related entities) and now you want to change the graph. Your new graph is extracted from web request which mean it is detached and EF doesn’t know what has changed. You must do it manually – I just discussed what does it mean to do it manually in another question = it is usually too complex.

    The easiest way is your current approach – delete everything and add it again but it is really ugly. Another approach is loading the graph from database and manually merge all changes you get from the request = compare these two graph and update the loaded (attached). Be aware that you must manually call DeleteObject for anything you want to delete from the database. Then just call SaveChanges.

    Btw. if you are doing wizard why don’t you just store current state in session and save everything once user completes the wizard? You will avoid all these complications.

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

Sidebar

Related Questions

I have a table which has a header row, but also a header column
I have a table which has employee relationship defined within itself. i.e. EmpID Name
Have a linking (or ref) table which has a dual primary key. Need to
I have a table which contains contact information. This table has 1 column relevant
I have a simple question which propably has a difficult answer, but what is
2 databases QF AND TK QF has the following: Imagine you have a table
I have a query that pulls up questions from one table and answers from
I have three tables. This query will write down the right answer (x-lines for
I actually have an answer to my question but it is not parallelized so
Can anybody have good answer when should be database driven development be used and

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.