filmov
tv
Part 5 How to handle model changes in entity framework
Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
Entity Framework - All Text Articles
Entity Framework - All Slides
Entity Framework Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
In this video we will discuss, how to handle model changes after the database is already created. This is continuation to Part 4. Please watch Part 4 before proceeding.
Based on Employee class Entity Framework has auto-generated table tblEmployees.
By default, an error will be thrown if the model changes after the database is created. This is because the Model and Database are no longer in sync. To check if the model has changed since the database was created, entity framework uses _MigrationHistory table that is auto-generated.
Database.SetInitializer(new DropCreateDatabaseIfModelChanges[EmployeeDBContext]());
Another option you have here is, to drop and recreate the database always. To drop and recreate the database always we would change the code in Application_Start() method as shown below.
Database.SetInitializer(new DropCreateDatabaseAlways[EmployeeDBContext]());
Please Note: Database class is present in System.Data.Entity namespace.
Run the application, and notice that the database is dropped and recreated. But the webform does not display any data, as there is no data in Departments and tblEmployees tables. For now let's manually populate the tables using SQL script.
Referesh the webform. Notice that JobTitle is not displayed on the WebForm. To fix this add a boundfield to the GridView control that displays Employees details.
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
Entity Framework - All Text Articles
Entity Framework - All Slides
Entity Framework Playlist
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
In this video we will discuss, how to handle model changes after the database is already created. This is continuation to Part 4. Please watch Part 4 before proceeding.
Based on Employee class Entity Framework has auto-generated table tblEmployees.
By default, an error will be thrown if the model changes after the database is created. This is because the Model and Database are no longer in sync. To check if the model has changed since the database was created, entity framework uses _MigrationHistory table that is auto-generated.
Database.SetInitializer(new DropCreateDatabaseIfModelChanges[EmployeeDBContext]());
Another option you have here is, to drop and recreate the database always. To drop and recreate the database always we would change the code in Application_Start() method as shown below.
Database.SetInitializer(new DropCreateDatabaseAlways[EmployeeDBContext]());
Please Note: Database class is present in System.Data.Entity namespace.
Run the application, and notice that the database is dropped and recreated. But the webform does not display any data, as there is no data in Departments and tblEmployees tables. For now let's manually populate the tables using SQL script.
Referesh the webform. Notice that JobTitle is not displayed on the WebForm. To fix this add a boundfield to the GridView control that displays Employees details.
Комментарии