Data Access has been discontinued. Please refer to this page for more information.

Explicitly Marking an Object as Changed

By default the OpenAccessContext silently manages the change tracking of the persistent objects. However, this is not possible for all types of fields that a class may contain. For example, changes in array fields could not be fully tracked by the object context. This limitation is present when an array field is not completely replaced with another array but only a certain element is changed. When you change some value of an array, you will have to inform the context that you have made a change, so that it can be persisted to the database. You have to use the MakeDirty method like in the example below.

using (FluentModel dbContext = new FluentModel())
{
   Category category = dbContext.Categories.FirstOrDefault();
   category.Picture[0] = Convert.ToByte(150);

   IList<Category> dirtyCategories = dbContext.GetChanges().GetUpdates<Category>();
   Debug.Assert(dirtyCategories.Count == 0);

   dbContext.MakeDirty(category, "Picture");
   dirtyCategories = dbContext.GetChanges().GetUpdates<Category>();

   Debug.Assert(dirtyCategories.Count == 1);

   dbContext.FlushChanges();
   dirtyCategories = dbContext.GetChanges().GetUpdates<Category>();
   Debug.Assert(dirtyCategories.Count == 0);
}
Using dbContext As New FluentModel()
 Dim _category As Category = dbContext.Categories.FirstOrDefault()
 _category.Picture(0) = Convert.ToByte(150)

 Dim dirtyCategories As IList(Of Category) = dbContext.GetChanges().GetUpdates(Of Category)()
 Debug.Assert(dirtyCategories.Count = 0)

 dbContext.MakeDirty(_category, "Picture")

 dirtyCategories = dbContext.GetChanges().GetUpdates(Of Category)()
 Debug.Assert(dirtyCategories.Count = 1)

 dbContext.FlushChanges()
 dirtyCategories = dbContext.GetChanges().GetUpdates(Of Category)()
 Debug.Assert(dirtyCategories.Count = 0)
End Using