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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:14:30+00:00 2026-05-31T22:14:30+00:00

I have a simple relationship. A campaign is linked to two Pages. A page

  • 0

I have a simple relationship. A campaign is linked to two Pages. A page can only be linked to one campaign. But I keep running into this error:

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

I went looking through some example codes and tutorials while comparing it to my code but I can’t find a mistake.

 public class Campaign
    {
        [Key()]
        public int Campaignid { get; set; }
        public string Name { get; set; }

        public virtual Page LandingPage { get; set; }
        public virtual RedeemPage RedeemPage { get; set; }
    }


public class Page
{
    [Key()]
    public int PageContentId { get; set; }
    public string Logo { get; set; }
    public string Css { get; set; }

    [ForeignKey("Campaign")]
    public int campaignID { get; set; }
    public virtual Campaign Campaign { get; set; }
}

Edit

Followed Eranga’s reply and used the Fluent API instead but now I’m getting:

An error occurred while saving entities that do not expose foreign key
properties for their relationships

  • 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-31T22:14:31+00:00Added an answer on May 31, 2026 at 10:14 pm

    The Data annotations mapping is confusing in this scenario. Use the Fluent API to configure. Remove the data annotations for navigational property mapping and use fluent API as follows.

    class MyContext : DbContext
    {
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Campaign>().HasRequired(x => x.LandingPage)
               .WithMany();
    
            modelBuilder.Entity<Page>().HasRequired(x => x.Campaign)
               .WithMany()
               .HasForeignKey(x => x.campaignID); 
    
          base.OnModelCreating(modelBuilder);
        }
    }
    

    Edit

    The problem after setting WillCascadeOnDelete(false) is that both Campaign and Page has auto incremented PKs and you have a 1-to-1 mapping. Hence to save one record it needs the Id of the other inserted row and that other row need the id of the 1st row.

    You can either change the PK to be a GUID or make 1 FK to be nullable and call to SaveChanges twice. Eg

    Changing the relationship to nullable

        modelBuilder.Entity<Campaign>().HasOptional(x => x.LandingPage)
           .WithMany();
    
    
    using(var scope = new TransactionScope())
    {
    
           context.Campaigns.Add(campaign);
           context.SaveChanges();
    
           page.CampaignId = campaign.CampaignId;
           context.Pagess.Add(page);
           context.SaveChanges();
    
           scope.Complete();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
I have a simple has_one/belongs_to relationship between two models. This is a new association
I have a simple one-to-many relationship. I would like to select rows from the
I have a simple situation where I have two entities related with Many-To-Many relationship.
I have a simple application using ADO.NET EntityFramework using a many-to-many relationship between two
I have some simple Code First classes with a Many to One relationship. If
I'm creating a (theoretically) simple hasMany relationship within a domain class. I have two
I have a fairly simple foreign key relationship displayed by an inline in Django's
I'm getting started with FubuMVC and I have a simple Customer -> Order relationship
I have simple static lib in xcode with the only class test.h: @interface TestClass

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.