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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:40:41+00:00 2026-05-23T09:40:41+00:00

Hallo everybody, i have the following simple models. public class A { public B

  • 0

Hallo everybody,

i have the following simple models.

public class A
{
    public B B { get; set; }
    public C C { get; set; }

}

public class B
{
    public int Id { get; set; }


}

public class C
{
    public int Id { get; set; }

}

I get an error while i am trying to get the data:

System.Data.Edm.EdmEntityType: :
EntityType ‘A’ has no key
defined. Define the key for this
EntityType.

Previous it was done via “RelatedTo”. Has anybody a solution for this problem with the help of an example?

Thanks in advance!

  • 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-23T09:40:41+00:00Added an answer on May 23, 2026 at 9:40 am

    Each entity in EF must have a primary key. It looks like A is junction table for many to many so you have multiple choices.

    Remove A totaly and let EF handle many-to-many:

    public class B
    {
        public int Id { get; set; }
        public virtual ICollection<C> Cs { get; set; }
    }
    
    public class C
    {
        public int Id { get; set; }
        public virtual ICollection<B> Bs { get; set; }
    }
    

    If you want A as entity you must either define additional key:

    public class A
    {
        public int Id { get; set; }
        public B B { get; set; }
        public C C { get; set; }
    }
    

    or you must include FK properties for B and C and mark them both as composite primary key (should be in db as well):

    public class A
    {
        public int bId { get; set; }
        public int cId { get; set; }
        public B B { get; set; }
        public C C { get; set; }
    }
    

    Edit:

    Mapping for the last solution

    modelBuilder.Entity<A>.HasKey(a => new { a.bId, a.cId });
    modelBuilder.Entity<A>.HasRequired(a => a.B)
                          .WithMany()
                          .HasForeignKey(a => a.bId);
    modelBuilder.Entity<A>.HasRequired(a => a.C)
                          .WithMany()
                          .HasForeignKey(a => a.cId);
    

    Anyway if your A looks exactly as you described without any other properties you are definitely doing it wrong. Mapping A is only needed when it contains anything else then navigation properties / FKs for modelling many-to-many relation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Everybody! I got the following error, while trying to test a code for
Hello everybody, I have this problem (title of the post). Failure/Error: get :create, :user
Hello everybody i have C++ tStringGrid I want to get string from specific cell
Everybody, Hello! I have a simple stub client for the cxf web-service (spring app).
Hello everybody I have a problem with exception. The following code block do this
Hallo, I want to get data into a database on a multicore system with
Hello everybody and sorry for the rather confusing question-title. I have a Hibernate Class
Hello everybody i'm trying to get the returned values from an apprequest invite so
Hello everybody and thanks for reading. I have this html; <i class=icon-plus icon-white> Test
Hallo everybody, I'm dealing with a pretty strange situation here. I have developed a

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.