1. Configuration Classes
Internal sealed class Configuration<tcontext>: dbmigrationsconfiguration<tcontext> where Tcontext: DbContext
{
Public Configuration ()
{
Automaticmigrationsenabled = true;
Automaticmigrationdatalossallowed = true;
}
protected override void Seed (Tcontext context)
{
}
}
2. Initialize class
public class Schoolcontext:dbcontext
{
Public Schoolcontext (): Base ("Name=test")
{
}
Static Schoolcontext ()
{
Database.setinitializer (New Migratedatabasetolatestversion<schoolcontext, configuration<schoolcontext> > ());
}
protected override void Onmodelcreating (Dbmodelbuilder modelBuilder)
{
ModelBuilder.Configurations.AddFromAssembly (assembly.getexecutingassembly ());
}
}
3. Entity classes
public class Course {public int StudentID {get, set;} public string Name {get; set;}}
Good. Get. It's so simple. I also studied for half a day, read a lot of information. You can modify the entity class to see how the database changes.
EF automatically modifies the database