Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
namespace MVCExams.Models
{
[Table("adminreg")]
public class admin
{
public int recid { get; set;}
public string name { get; set; }
public string userid { get; set; }
public string emailid { get; set; }
public string pswrd { get; set; }
}
}
{"One or more validation errors were detected during model generation:\r\n\r\nMVCExams.Models.admin: : EntityType 'admin' has no key defined. Define the key for this EntityType.\r\nadmins: EntityType: EntitySet 'admins' is based on type 'admin' that has no keys defined.\r\n"}

What I have tried:

i tried to change primary key name and all then also it shows same
Posted
Updated 21-Sep-16 20:55pm

1 solution

Entity Framework uses a primary key field to create the primary key column on the generated table.

It identifies column name "Id" as primary key .In your case if recid is the primary key please add [key] attribute and try.


[key]
public int recid { get; set;}


Please read below .

Entity Framework Code First Data Annotations[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900