Hello,
In my project I am working with an SQL database and entity framework.
I am using the Unit of Work pattern to manage the different data sets and commit changes to it.
The object sets are created as follows:
private IObjectSet<DataObject> dataObjects;
public IObjectSet<DataObject> DataObjects
{
get
{
if (dataObjects == null)
{
dataObjects = context.CreateObjectSet<DataObject>();
}
return dataObjects;
}
}
My question is related to the updating of the datasets that are contained in the Unit of Work. When first creating a data set, they are filled correctly with data from the database.
However, when any property of any of these data objects is changed from a different location, it is not updated in my Unit of Work. When I now try to execute a query on the (modified) object set, the result is based on the data from the database, even though the data set from my Unit of Work still contains the old (unmodified) data.
The correct object is retrieved from the query (as based on the database), while the data contained in the retrieved object (as based on the Unit of Work) is not.
By adding
context.Refresh(RefreshMode.StoreWins, dataObjects);
to the ObjectSet, the correct value is retrieved, but I wonder if this is the best solution.
How is it possible that objects are correctly added and removed from the data set at runtime, but changes to the object's properties are not registered in the unit of work.
Thank you in advance.