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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:47:47+00:00 2026-05-22T23:47:47+00:00

Another ‘Entity Type ‘x’ has no key defined’ question, but I’ve set the [Key]

  • 0

Another ‘Entity Type ‘x’ has no key defined’ question, but I’ve set the [Key] attribute on a property so I’m a bit confused.

Here’s my entity and context classes:

namespace DoctorDB.Models
{
    public class Doctor
    {
        [Key]
        public string GMCNumber;
        [Required]
        public string givenName;
        [Required]
        public string familyName;
        public string MDUNumber;
        public DateTime MDUExpiry;
        public string MDUCover;
    }

    public class DoctorContext : DbContext
    {
        public DbSet<Doctor> Doctors { get; set; }
    }
}

When I go to create my controller, I’ve selected to create it with the Entity Framework methods using this entity and context:

enter image description here

and I get this error:

enter image description here

My only thought is whether you can’t successfully use [Key] on a string property. If you can’t then fair enough, I’ll work round it, but I’d be grateful if someone could confirm this one way or the other.

  • 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-22T23:47:48+00:00Added an answer on May 22, 2026 at 11:47 pm

    You need to change GMCNumber to a property not a field.

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

Sidebar

Related Questions

Another day , another question. My service layer has the following method public MatchViewData
Another question which has me perplexed: I have a table which enables users to
Another SCJP question. I think the output is K=7, but the book's answer is
Another poster asked about preferred syntax for infinite loops . A follow-up question: Why
Another question asked about determining odd/evenness in C, and the idiomatic (x & 1)
another issue in IE 6... link The navbar link list has a border applied
Another basic Rails question: I have a database table that needs to contain references
Another clipboard question: When text is put onto the clipboard, it frequently goes in
Another question related to this one . I have a List<SortableObjects> that is the
Another developer created a stored procedure that is set up to run as 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.