Best way to keep ObservableCollection and ObjectContext in sync?

I have a combo box bound to an ObservableCollection of People (a set of entity framework objects that I retrieve in response to a user request: search box), then I have functions like Edit, Delete and Add New. At the moment I am just making sure that every time I add or remove something from the database, I am also working with OC. Is there a better way to handle this?

Thank you, Cohan.

+2


source to share


1 answer


I found that you might need to control the OC when it comes to manipulating the EF. For example when you add a new item to DB

private bool AddItems(Item item)
{
    bool addSucceed = false;

    // Do adding ...

    if(addSucceed)
        MyObservableCollection.Remove(item)
    else
        // Error notificaiton here.
}

      



Hope it helps.

+3


source







All Articles