Community & Support
Home / Community & Support / Knowledge Base / Telerik OpenAccess ORM / General / Handling the ‘Explicit change tracking required for the array field…’ warning

Handling the ‘Explicit change tracking required for the array field…’ warning

Article Info

Rating: Not rated

Article information

Article relates to

 Telerik OpenAccess ORM

Created by

 Alexander Filipov

Last modified

 October 22, 2009

Last modified by

 Alexander Filipov


DESCRIPTION
By default the IObjectContext (implemented by the ObjectScope and ObjectContainer classes) 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 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

SOLUTION
The code below would not persist the change in the byte[] field named Picture from the Category object:
//C#
Category category = scope.Extent<Category>().First();
scope.Transaction.Begin();
 
category.Picture[1] = 0;
 
scope.Transaction.Commit();
'VB.NET
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#
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();
'VB.NET
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#
Category category = scope.Extent<Category>().First();
scope.Transaction.Begin();
 
byte[] newPicture = new byte[] {0,1,2};
category.Picture = newPicture;
 
scope.Transaction.Commit();
'VB.NET
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()

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.