I'm working on an application which will use EF5 as ORM.
Before start, I needed to create tests to confirm that everything in EF5 is working as it should. One of things I tested was support for UnitOfWork. I simulated multiple units of work by creating multiple instances of DbContext (like multiple requests when DbContext lifetime is set to PerWebRequest in IOC).
I encountered a suprise there, as EF5, as it seems uses something like SqlDependency, because I have situation as folows:
DbContext unit1 = new DbContext(), unit2 = new DbContext();
unit1.Items.Add(new Item() { Name = "Item1" });
Assert.AreEqual(0, unit1.Items.ToList().Count); // true as item is in unit1.Items.Local collection
Assert.AreEqual(0, unit2.Items.ToList().Count);
unit1.SaveChanges();
Assert.AreEqual(1, unit1.Items.ToList().Count); // true as unit1 is saved
Assert.AreEqual(1, unit2.Items.ToList().Count); // true as unit2 is somehow notified of changes
I am trying to find documentation but neither EF project pages and blogs nor google help me. This is not how old version of EF worked, where there was no out of the box feature to notify other contexts (i.e. see this question). It is nice if this is implemented but I need document which says it is, because I'm afraid that I cannot rely on this feature, and I cannot rely on knowing that data in my context won't change if other unit of work completes, as here obviously does.