Reputation: 69
I'm failing to understand why changes aren't detected before I actually apply SaveChanges method. I'm just testing things around. Here is the code:
Lodging query = context.Lodgings.SingleOrDefault(d => d.LodgingName == "Hotel4");
context.Entry(query).Reference(l=>l.Destination).Load();
Console.WriteLine(query.Destination.DestinationName);
query.Destination.DestinationName = "Some Where Else";
Console.WriteLine(context.Entry(query).State);
Console.WriteLine(query.Destination.DestinationName);
context.ChangeTracker.DetectChanges();
Console.WriteLine(context.Entry(query).State);
Console.WriteLine(query.Destination.DestinationName);
The output is "Unchanged". Of course if I save the changes the database will be updated.
Upvotes: 1
Views: 161
Reputation: 339
Your question doesnt explain about actual requirement.May be you will find the answer here.
Upvotes: 1
Reputation: 927
Maybe this explanation can help: http://blog.oneunicorn.com/2012/03/10/secrets-of-detectchanges-part-1-what-does-detectchanges-do/
Upvotes: 1