Haytham Bustami
Haytham Bustami

Reputation: 69

Detecting Changes with DBContext

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

Answers (2)

Daryl
Daryl

Reputation: 339

Your question doesnt explain about actual requirement.May be you will find the answer here.

Upvotes: 1

Related Questions