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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:22:36+00:00 2026-06-09T14:22:36+00:00

I am trying to create my first mvc class and am having an issue

  • 0

I am trying to create my first mvc class and am having an issue getting started.
I am using a shared database on my hosting account and have created the following class

namespace MvcApplication2.Models
{
    public class tUsers
    {

            public int UserID { get; set; }
            public string Username { get; set; }
            public string UserEmail { get; set; }
            public string UserPassword { get; set; }
            public int GroupId { get; set; }


    }

    public class tUsersDBContext : DbContext
    {
        public DbSet<tUsers> tUsers { get; set; }
    }
}

and here is my connection string

   <add name="DefaultConnection" connectionString="Data Source=gdfgdfgdfg;Initial Catalog=fsdf_fdsf;Persist Security Info=True;User ID=ddd_reddntal;Password=fgfggfdg" providerName="System.Data.SqlClient" />

the error i get is

Unable to retrieve metadata for ‘mvcapplication2.models.tusers’ one or
more validation errors were detected during model generation:

Entity type users has no defended key.

Also do my model names need to match my table names exact?

  • 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-06-09T14:22:37+00:00Added an answer on June 9, 2026 at 2:22 pm

    Entity Framework can not identify the primary key property of your tUsers class. Annotate UserID property with Key attribute. If your table name is different from the class name use the Table attribute to specify the table name.

    Try to use proper naming conventions for class names. In this case it should be User not tUsers.

    [Table("MyTableName")]
    public class tUsers
    {       
            [Key]
            public int UserID { get; set; }
            public string Username { get; set; }
            public string UserEmail { get; set; }
            public string UserPassword { get; set; }
            public int GroupId { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a many-to-many relationship using EF code first in my MVC
I am trying to create my first GUI application using (Java + Eclipse +
I'm using opengl and trying to create a first person camera. All examples use
I'm new to NHibernate and trying to create my first mapping. I have created
I'm trying to make this 2-player web game application using Spring MVC. I have
I am using MVC-Viewmodel EF Model First, I am trying to make 2 forms
I trying to do something like that First, Create a new mvc 3 project
I am using Entity Framework code first and ASP.NET MVC 3. I have the
I'm using Ninject with an MVC app, also using EF4.1 Code First. I'm getting
I'm trying to create a form using Spring @MVC 3.0. This form is supposed

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.