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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:50:11+00:00 2026-06-02T14:50:11+00:00

I have a wizard step in which a user fills in fields. I then

  • 0

I have a wizard step in which a user fills in fields. I then use json to save the values into my database for each wizard step.
However, in my repository I have my savechanges(). But it wont save the changes, instead it throws an error:

Entities in ‘NKImodeledmxContainer.SelectedQuestion’ participate in the ‘QuestionSelectedQuestion’ relationship. 0 related ‘Question’ were found. 1 ‘Question’ is expected.

Anyone know how to get rid of the error? Do I have to get the ID from Question and save it aswell to my database or can I change something in EF so the error message is not getting thrown?

This is my post in my controller:

        [HttpPost]
    public JsonResult AnswerForm(int id, SelectedQuestionViewModel model)
    {
        bool result = false;
        var goalCardQuestionAnswer = new GoalCardQuestionAnswer();
        goalCardQuestionAnswer.SelectedQuestion = new SelectedQuestion();

        goalCardQuestionAnswer.SelectedQuestion.Id = model.QuestionID;
        goalCardQuestionAnswer.Comment = model.Comment;
        goalCardQuestionAnswer.Grade = model.Grade;

            if (goalCardQuestionAnswer.Grade != null)
            {

                    answerNKIRepository.SaveQuestionAnswer(goalCardQuestionAnswer);
                    answerNKIRepository.Save();
                    result = true;
                    return Json(result);                   
            }

       answerNKIRepository.SaveQuestionAnswer(goalCardQuestionAnswer);
       answerNKIRepository.Save();

        return Json(result);
    }

My Repository

    public class AnswerNKIRepository
{
    private readonly NKImodeledmxContainer db = new NKImodeledmxContainer();

    public List<SelectedQuestion> GetAllSelectedQuestionsByGoalCardId(int goalCardId)
    {
        return db.SelectedQuestion.Where(question => question.GoalCard.Id == goalCardId).ToList();
    }

    public void SaveQuestionAnswer(GoalCardQuestionAnswer goalCardQuestionAnswer)
    {
        db.GoalCardQuestionAnswer.AddObject(goalCardQuestionAnswer);
    }

    public void Save()
    {
        db.SaveChanges();
    }
}

This is my ViewModel:

 public class SelectedQuestionViewModel
{

    public int? Grade { get; set; }
    public string Comment { get; set; }
    public string SelectedQuestionText { get; set; }
    public int QuestionID { get; set; }
}

This is my database model:

enter image description here

  • 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-02T14:50:12+00:00Added an answer on June 2, 2026 at 2:50 pm

    The exception complains that SelectedQuestion.Question is a required navigation property but you don’t set this property in your code. Try to load the question by Id from the repository and set it to the SelectedQuestion.Question reference: Replace this line …

    goalCardQuestionAnswer.SelectedQuestion.Id = model.QuestionID;
    

    …by…

    goalCardQuestionAnswer.SelectedQuestion.Question =
        answerNKIRepository.GetQuestionById(model.QuestionID);
    

    And in your repository add the method:

    public Question GetQuestionById(int id)
    {
        return db.Question.Single(q => q.Id == id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MFC app which is wizard based. The App asks a user
I have a three step wizard. On the first step I use a repeater
I have a simple web application in which I have created a wizard, each
I have an AJAX powered form which is more like a 5 step wizard.
I have a User model in my app, which I would like to store
Excel 2007: I have an app which outputs several rows, with pipe delimiters, into
I have the following line in a JSF page: <h:commandLink action=#{myBean.test} value=Wizard Step></h:commandLink> I
I have found great jQuery wizard here Jerod Santo blog which suits my need.
I'm using a JTabbedPane to hold each step in the wizard that I am
I have a custom CreateUserWizard in which the user gives his email as username.

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.