vendredi 11 septembre 2015

Entities tracking in Entity Framework

I started reading more about EF. I believed that entities are tracked as long as the context is in scope. But when I try the code below I get different results. I'm sure I misunderstood what I read. Can you please explain.

Destination canyon;
DbEntityEntry<Destination> entry;
using (var context = new BreakAwayContext())
      {
          canyon = (from d in context.Destinations.Include(d => d.Lodgings)
                    where d.Name == "Grand Canyon"
                    select d).Single();
          entry = context.Entry<Destination>(canyon);
      }
Console.WriteLine(entry.State); //Unchanged
canyon.TravelWarnings = "Carry enough water!";
Console.WriteLine(entry.State); //Modified



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire