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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:10:28+00:00 2026-05-29T20:10:28+00:00

I’m new to .NET MVC and I’m struggling with using Code First with an

  • 0

I’m new to .NET MVC and I’m struggling with using Code First with an existing database in which a table has a one to none-or-one (1 -> 0..1) relationship.

I have a report, which can have many sections, and each section can have many questions. Now here’s the bit where I think I’m running into trouble… each question may have one answer or none.

I’m getting the following error:

System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role
‘QuestionAnswer_Question_Source’ in relationship
‘QuestionAnswer_Question’. Because the Dependent Role properties are
not the key properties, the upper bound of the multiplicity of the
Dependent Role must be �*�.

Here are my model classes:

ModeratorReport.cs

public class ModeratorReport
{
    [Key, Column(Order = 0)]
    public int ModeratorReportID { get; set; }

    [Key, Column(Order = 1)]
    public string Status { get; set; }

    public string FileYear { get; set; }
    public string SessionCode { get; set; }
    public string CentreNumber { get; set; }
    public string SubjectNumber { get; set; }
    public string PaperNumber { get; set; }
    public string ModeratorNumber { get; set; }
    public DateTime? DateModified { get; set; }

    public virtual ICollection<AuditItem> Audit { get; set; }
}

Section.cs

public class Section
{
    [Key]
    public int SectionID { get; set; }
    public string SectionEnglish { get; set; }
    public string SectionWelsh { get; set; }

    public virtual ICollection<Question> Questions { get; set; }
}

Question.cs

public class Question
{
    [Key]
    public int QuestionID { get; set; }

    [ForeignKey("Section")]
    public int SectionID { get; set; }

    public string QuestionEnglish { get; set; }
    public string QuestionWelsh { get; set; }
    public string Type { get; set; }

    public virtual Section Section { get; set; }
    public virtual QuestionAnswer QuestionAnswer { get; set; }
}

QuestionAnswer.cs

public class QuestionAnswer
{
    [Key]
    public int AnswerID { get; set; }

    [ForeignKey("ModeratorReport"), Column(Order = 0)]
    public int ModeratorReportID { get; set; }
    [ForeignKey("ModeratorReport"), Column(Order = 1)]
    public string Status { get; set; }

    [ForeignKey("Section")]
    public int SectionID { get; set; }

    [ForeignKey("Question")]
    public int QuestionID { get; set; }

    public string Answer { get; set; }

    public virtual ModeratorReport ModeratorReport { get; set; }
    public virtual Section Section { get; set; }
    public virtual Question Question { get; set; }
}

I also have a one-to-many relationship with ModeratorReport and Audit but I don’t think that is what is causing the error.

Any help would be appreciated.

Thanks.

  • 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-29T20:10:29+00:00Added an answer on May 29, 2026 at 8:10 pm

    The EF is complaining because it sounds like you are using an FK Association – which means that the QuestionID is a property of the Entity and there is a Question reference too – and you can’t do this with FK Associations.
    if you remove the QuestionID from QuestionAnswer it should work

    public class QuestionAnswer
    {
        [Key,ForeignKey("Question")]]
        public int AnswerID { get; set; }
    
        [ForeignKey("ModeratorReport"), Column(Order = 0)]
        public int ModeratorReportID { get; set; }
        [ForeignKey("ModeratorReport"), Column(Order = 1)]
        public string Status { get; set; }
    
        [ForeignKey("Section")]
        public int SectionID { get; set; }
    
    
        public string Answer { get; set; }
    
        public virtual ModeratorReport ModeratorReport { get; set; }
        public virtual Section Section { get; set; }
        public virtual Question Question { get; set; }
    }
    

    I would suggest you to use fluent mapping which is more clear:

    modelBuilder.Entity<Question>()
                .HasOptional(q => q.QuestionAnswer)
    
    modelBuilder.Entity<QuestionAnswer>()
                    .HasRequired(qa => qa.Question)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.