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

Explicitly Marking an Object as Changed

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

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. To notify the programmer for this behavior, Telerik Data Access shows a warning at compile time with this limitation.

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 (EntitiesModel dbContext = new EntitiesModel())
{
   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 EntitiesModel()
 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