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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:24:45+00:00 2026-05-27T01:24:45+00:00

I have a trouble as description below: One or more validation errors were detected

  • 0

I have a trouble as description below:

One or more validation errors were detected during model generation:

System.Data.Edm.EdmAssociationType: : Multiplicity conflicts with the referential constraint in Role 'CorpQuestionA_CorpQAnswer_Source' in relationship 'CorpQuestionA_CorpQAnswer'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.

My database as screen-shot pic:
http://i.6.cn/cvbnm/18/e0/23/da82be1ab8adfcd84f68d1a46d645e97.jpg

and the entity define:

public class CorpQuestionA 
{ 
    [Key] 
    public Guid cqua_QuestionId { get; set; } 
    public Guid cqua_CorpId { get; set; } 
    [MaxLength] 
    public string cqua_Question { get; set; } 
    public DateTime cqua_Date { get; set; } 
    public Boolean cqua_IsAnswer { get; set; } 

    [ForeignKey("cqua_CorpId")] 
    public virtual CorpRegInfo510112 CorpRegInfo510112 { get; set; } 
    public virtual CorpQAnswer CorpQAnswer { get; set; } 
} 


public class CorpQAnswer 
{ 
    [Key] 
    public Guid cqan_QuestionId { get; set; } 
    public string cqan_Answer { get; set; } 

    [ForeignKey("cqan_QuestionId")] 
    public virtual CorpQuestionA CorpQuestionA { get; set; } 
} 

then is the ProjectDataEntities file:

public class ProjectDataEntities : DbContext 
{ 
    public DbSet<CorpQuestionA> Tbl_CorpQuestionAs { get; set; } 
    public DbSet<CorpQAnswer> Tbl_CorpQAnswers { get; set; } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
        base.OnModelCreating(modelBuilder); 
        modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); 

        modelBuilder.Entity<CorpQuestionA>().ToTable("tbl_CorpQuestionA"); 
        modelBuilder.Entity<CorpQAnswer>().ToTable("tbl_CorpQAnswer"); 

        //Todo: Add custom mapping rules here... 
        modelBuilder.Entity<CorpQuestionA>().HasOptional(p => p.CorpQAnswer).WithOptionalPrincipal(x => x.CorpQuestionA);//.Map(p => p.MapKey("cqua_QuestionId")); 
    } 
}

when I do update operate, it throws a exception as description before

public bool AnswerCorpQuestion(AnswerCorpQuestionModel acqModel) 
    { 
        var prjPO = new ProjectDataEntities(); 

        //update table CorpQuestionA  
        CorpQuestionA cqaModel0 = prjPO.Tbl_CorpQuestionAs.Find(acqModel.cqua_QuestionId); 
        cqaModel0.cqua_IsAnswer = acqModel.cqua_IsAnswer; 

        //insert table CorpQAnswer  
        CorpQAnswer cqaModel1 = new CorpQAnswer 
        { 
            cqan_QuestionId = acqModel.cqua_QuestionId, 
            cqan_Answer=acqModel.cqan_Answer 
        }; 
        prjPO.Tbl_CorpQAnswers.Add(cqaModel1); 

        try 
        { 
            prjPO.SaveChanges(); 
            return true; 
        } 
        catch(DbEntityValidationException dbEx) 
        { 
            throw dbEx; 
        } 
    }

Waiting for help, thx

  • 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-27T01:24:45+00:00Added an answer on May 27, 2026 at 1:24 am

    Change the shared primary key as follows.

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
        base.OnModelCreating(modelBuilder); 
        modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); 
    
        modelBuilder.Entity<CorpQuestionA>().ToTable("tbl_CorpQuestionA"); 
        modelBuilder.Entity<CorpQAnswer>().ToTable("tbl_CorpQAnswer"); 
    
        modelBuilder.Entity<CorpQuestionA>().HasOptional(p => p.CorpQAnswer)
           .WithRequired(x => x.CorpQuestionA);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the jsf code and css code below. I'm having trouble getting the
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble with the following piece of code. When I go through with
I have trouble using Perl grep() with a string that may contain chars that
I have trouble defining a trigger for a MySQL database. I want to change
I have trouble when designing classes like this class C1 { public: void foo();
I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different
I have trouble where, for some reason, SVN would only merge the newly generated
I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish
I have trouble finding way to correctly refactor this code so that there would

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.