As the application grows, we will want to add new properties to existing entities let's try doing this and see what happens
Add new property
Replace the student class with the one shown below
namespaceEFGetStarted{publicclassStudent {publicint Id { get; set; }publicstring Name { get; set; }publicbool IsEnrolled { get; set; }publicstring City { get; set; } }}
Run the application now with the following code in the program class
usingEFGetStarted;usingSystem;usingSystem.Linq;var db =newMyContext();Console.WriteLine("List of students...\n");foreach (var s indb.Students)Console.WriteLine($" Id: {s.Id}\t Name: {s.Name} Is Enrolled: {s.IsEnrolled}");Console.WriteLine();Console.WriteLine("Press any key to exit");Console.ReadKey();
What happens?
You will see that the application throws an exception saying that the city column is invalid!
This is because the entity or the Student model is not In Sync with the database!