Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Handle the Explicit change tracking required for the array field warning
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > How to: Handle the Explicit change tracking required for the array field warning

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

By default the IObjectContext (implemented by the ObjectScope and ObjectContainer classes) silently manages the change tracking of the 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 certain element is changed. To notify the programmer for this behavior, Telerik OpenAccess ORM shows a warning at compile time with the following text:

OpenAccess Warning: Explicit change tracking required for the array field Namespace.ClassName.FieldName

The code below would not persist the change in the byte[] field named Picture from the Category object:

C# Copy Code
Category category = scope.Extent<Category>().First();
scope.Transaction.Begin();
category.Picture[1] = 0;
scope.Transaction.Commit();  
VB.NET Copy Code
Dim category As Category = scope.Extent(Of Category)().First()
scope.Transaction.Begin()
category.Picture(1) = 0
scope.Transaction.Commit()

As the warning states, explicit change tracking is required in this case. This can be accomplished by using the IObjectContext.MakeDirty(object persistentObject, string fieldname) method. It marks a field as "dirty", thereby the field value is forced to be stored in the database. Below is the same sample code that modifies one of the array elements but this time the change is persisted. Note that the MakeDirty() method should be called before the change is made.

C#

Copy Code
Category category = scope.Extent<Category>().First();
scope.Transaction.Begin();
// mark the field as dirty
scope.MakeDirty(category, "Picture");
category.Picture
[1] = 0;
scope.Transaction.Commit();  
Example Title Copy Code
Dim category As Category = scope.Extent(Of Category)().First()
scope.Transaction.Begin()
' mark the field as dirty
scope.MakeDirty(category, "Picture")
category.Picture(1) = 0
scope.Transaction.Commit()

The case when the whole array is replaced with another array does not require any additional operations. The change tracking is done internally:

C# Copy Code
Category category = scope.Extent<Category>().First();
scope.Transaction.Begin();
byte[] newPicture = new byte[] {0,1,2};
category.Picture = newPicture;
scope.Transaction.Commit();  
VB.NET Copy Code
Dim category As Category = scope.Extent(Of Category)().First()
scope.Transaction.Begin()
Dim newPicture() As Byte = {0,1,2}
category.Picture = newPicture
scope.Transaction.Commit()