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?
Entity Framework can not identify the primary key property of your
tUsersclass. AnnotateUserIDproperty withKeyattribute. If your table name is different from the class name use theTableattribute to specify the table name.Try to use proper naming conventions for class names. In this case it should be
UsernottUsers.