Example #1
0
 public static void Audit()
 {
     using (var context = new UniversityDB())
     {
         var student = context.Students.Find(1);
         // Change value directly in the DB
         using (var contextDB = new UniversityDB()) {
             contextDB.Database.ExecuteSqlCommand("UPDATE Student SET PIB = PIB + ' DB' WHERE ID = 1");
         }
         // Change the current value in memory
         student.PIB = student.PIB + " Memory";
         string value = context.Entry(student).Property(m => m.PIB).OriginalValue;
         Console.WriteLine(string.Format("Original Value : {0}", value));
         value = context.Entry(student).Property(m => m.PIB).CurrentValue;
         Console.WriteLine(string.Format("Current Value : {0}", value));
         value = context.Entry(student).GetDatabaseValues().GetValue <string>("PIB");
         Console.WriteLine(string.Format("DB Value : {0}", value));
     }
 }