views:

23

answers:

1

Using Entity Framework 4.0 in C# / .NET 4.0.

Within my Entity model, I have an object (MyObject) that is part of a one-to-many relationship that produces a Navigation Property of the type EntityCollection<OtherObject>. Snippet of the generate code:

public partial class MyObject : EntityObject
{
    /* other code */

    public EntityCollection<OtherObject> OtherObjects
    {
        get { /* RelationshipManager stuff */ }
        set { /* RelationshipManager stuff */ }
    }

    /* other code */
}

I load the data fine, everything is good. Then another process adds lines to the underlying OtherObject table. I want to be able to reload or refresh my entity collection in order to gain access to these new objects.

Is there any possible way to do this? Neither of the following attempts accomplish the task:

Context.Refresh(RefreshMode.StoreWins, myObject);
Context.Refresh(RefreshMode.StoreWins, myObject.OtherObjects);

I'd like to avoid having to unload the entire context (as this would force a save of any currently modified information, which is undesirable), so is there any way to get the newly added data into my local entity model?

Thanks.

+1  A: 
myObject.OtherObjects.Clear();
Context.AcceptAllChanges();
myObject.OtherObjects.Load();

Disclaimer: Not Tested.

Kamyar
Thank you! I was stuck in the rabbit hole of Refresh, Clear and Load should get me going in the right direction.
RandomUsername
@RandomUsername: Glad that could help you.
Kamyar