????????
????code first????????model???????????????????????????????????????????DropCreateDatabaseIfModelChanges?????????????????????????????????а????Щ????????????????????o????????????????????????????EF????????????????ɡ?
???????
????????NuGet
???????????

 

//?model
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public class Lesson {
public int lessonID { get; set; }
[Required]
[MaxLength(50)]
public string lessonName { get; set; }
[Required]
public string teacherName { get; set; }
public virtual UserInfo UserInfo{get;set;}
}
//??model
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public class Lesson {
public int lessonID { get; set; }
[Required]
[MaxLength(50)]
public string lessonName { get; set; }
[Required]
[MaxLength(10)]
public string teacherName { get; set; }
public virtual UserInfo UserInfo{get;set;}
}

?????????????????????teacherName???????????????????
??????????????????????????model????????У????????????????????????????????д???ε?????nvarchar(max)????????nvarchar(10)??
????1????config????????????????
????<connectionStrings>
????<add name="TestUsersDB" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TestUsersDB;Data Source=XCL-PCSQLEXPRESS" providerName="System.Data.SqlClient" />
????</connectionStrings>
????2????NuGet???????