i find the problem when i tried to create a controller for sql server table,not code-first(localdb),and i check the connectionString ,but i think i hasn't mistakes on it
for safety ,i hide the machine-name,username and password
One or more validation errors were detected during model generation:
DB2Ex.Model.Student: : EntityType 'Student' has no key defined. Define the key for this EntityType.
Students: : EntityType 'Students' has no key defined. Define the key for this EntityType.
public class Student
{
public int xh { get; set; }
public string xm { get; set; }
public string xb { get; set; }
public string csrq { get; set; }
public string jg { get; set; }
public string sjhm { get; set; }
public string yxh { get; set; }
public string mm { get; set; }
}
public class StudentDBContext : DbContext
{
public StudentDBContext()
: base("schoolDB")
{
}
public DbSet<Student> Students { get; set; }
}
<add name="schoolDB" connectionString="Data Source=DESKTOP-*****;Initial Catalog=school;Persist Security Info=True;User ID=***;Password=***" providerName="System.Data.SqlClient" />
Studentclass. Perhaps you need to define one?