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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:39:56+00:00 2026-05-31T10:39:56+00:00

At start i wanted to mention that i’ve been fighting this thing for a

  • 0

At start i wanted to mention that i’ve been fighting this thing for a few days and tried many of the answers more or less related to this problem. Yet I could not resolve it.

I have two classes that represent tables in a DB. These are the existing tables used by legacy application and I cannot change them.

Message can have multiple MessageRecipients.

Environment: MVC3, EF4.1

Classes are:

public class Message
{
    [ForeignKey("MessageReciepients")]
    public virtual int MessageID { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public DateTime Recieved { get; set; }
    [ForeignKey("User")]
    public int AuthorUserID { get; set; }

    //P\\ Navigation properties
    public virtual IList<MessageRecipient> MessageReciepients { get; set; }
    public virtual User User { get; set; }
}

public class MessageRecipient
{
    //[Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int MessageID { get; set; }
    public int UserID { get; set; }
    public bool Read { get; set; }
    public bool Important { get; set; }
    public bool Deleted { get; set; }
    public bool Destroyed { get; set; }

    //P\\ Navigation Properties
    public virtual User User { get; set; }
}

The error I have is:

The foreign key component ‘MessageID’ is not a declared property on
type ‘MessageRecipient’. Verify that it has not been explicitly
excluded from the model and that it is a valid primitive property.

How to correctly map these classes, relationships to load the recipients of a message?

I can add that the navigation property User works correctly for a Message and loads a User’s data correctly.

I’m not too experienced with .NET and I learn while doing this.
I tried some EF API config to map these i tried swearing at it, curse it, and been close to cry and pray at the same time. No Joy!!

I would really appreciate the help.

  • 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-31T10:39:57+00:00Added an answer on May 31, 2026 at 10:39 am

    It turned out that the problem was with the composite key that i needed to use and it all could be solved with some attributes:

    This is how it looks now:

    public class Message
    {
        public int MessageID { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
        public DateTime Recieved { get; set; }
    
        [ForeignKey("User")]
        public int AuthorUserID { get; set; }
    
        //P\\ Navigation properties
        public virtual ICollection<MessageRecipient> MessageRecipients { get; set; }
        public virtual User User { get; set; }
    }
    
    public class MessageRecipient
    {
        [Key, Column(Order=0), ForeignKey("User")]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int UserID { get; set; }
    
        [Key, Column(Order = 1)]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int MessageID { get; set; }
    
        public bool Read { get; set; }
        public bool Important { get; set; }
        public bool Deleted { get; set; }
        public bool Destroyed { get; set; }
    
        //P\\ Navigation Properties
        public virtual User User { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you wanted to start a 'website' that could be accessible from multiple 'endpoints'.
I wanted to start a discussion about the details that you cover in your
Now that rvm seams to handle maglev with ease I wanted to start experimenting
For quite a long time I've wanted to start a pet project that will
I'm new to Git and this is really confusing. I wanted to start off
I don't know if this is a problem yet but wanted to start thinking
Not sure if I'm even calling this right but I wanted to start adding
I have an app that displays cartoon characters. I wanted to start to offer
I am to learn OpenCL and wanted to start out easy. I found and
I got the Wrox.Beginning.JavaScript.3rd.Edition and wanted to start learning it from scratch, then my

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.