I am seeing some undesired behavior when attempting to clear a navigation list property from the cache and re-query.
Example:
// User 1 queries for
contact Kelli Smith and looks up her work phone number.
Contact contact =
_manager.Contacts.Where(c => c.Person.LastName == "Smith"
&& c.Person.FirstName == "Kelli").Single();
Phone workPhone =
contact.Phones.Where(p => p.PhoneType.Name ==PhoneType.StandardPhoneNames.Work).FirstOrDefault();
Phone newPhone = null;
if (null
== workPhone)
{
// Kelli Smith has no work phone, so create
one, but do not yet save.
newPhone = Phone.Create(PhoneType.StandardPhoneNames.Work,
_manager);
newPhone.Number = "000";
contact.Phones.Add(newPhone);
}
// Meanwhile, User 2
saves a work phone number for Kelli Smith.
// User 1 wants to
refresh phone numbers for Kelli, so force cache to reload.
var f =
contact.EntityAspect.GetNavigationProperty("Phones");
f.GetEntityReference(contact).IsLoaded
= false;
f.GetEntityReference(contact).Load(MergeStrategy.OverwriteChanges);
workPhone = contact.Phones.Where(p
=> p.PhoneType.Name == PhoneType.StandardPhoneNames.Work).FirstOrDefault();
// Despite attempting
to clear the cache and reload, workPhone at this point is still the
// phone number
created (but not saved) above.
// Discard the created
but unsaved phone number...
newPhone.EntityAspect.RejectChanges();
// ...and our
navigation property now returns the phone number created and saved by User 2,
as desired.
workPhone = contact.Phones.Where(p
=> p.PhoneType.Name == PhoneType.StandardPhoneNames.Work).FirstOrDefault();
Is this the designed behavior? It so, how can I refresh a navigation property query without having to manually discard unsaved navigation list members?
Thanks.