Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

New Post: The changes to the database were committed successfully, but an error occurred while updating the object context.

$
0
0
I finally found my problem and as I suspected it was something stupid I did. In my model, I was building the query, loading values and returning a BindingList. What I did to fix it was to check to see if my BindingList was null, if it was I built the query, loaded the values and created the Binding List.

Original Code
public BindingList<StandardTerm> StandardTerms
{
    get
    {
        _uow.StandardTerms.FindAll().Load();
        _standardTerms = _uow.StandardTerms.GetBindingList();
    }
}
Correct Code
public BindingList<StandardTerm> StandardTerms
{
    get
    {
        if (_standardTerms == null)
        {
            _uow.StandardTerms.FindAll().Load();
            _standardTerms = _uow.StandardTerms.GetBindingList();
        }

        return _standardTerms;
    }
}
My repository class implements the method GetBindingList which is shown below.
protected DbSet<T> _set;
public BindingList<T> GetBindingList()
{
    return _set.Local.ToBindingList();
}
My entities all rely on the ObservableListSource which is described in the following MDSN article.

EF DataBinding with WinForms

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>