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

Getting an Object State

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.

Sometimes it can be useful to find exactly what is the state of a given entity. The OpenAccessContext class exposes the GetState method, which returns the state of a persistent object.

using ( EntitiesModel dbContext = new EntitiesModel() )
{
   Car newCar = dbContext.Cars.FirstOrDefault();
   newCar.Make = "NewMake";
   Telerik.OpenAccess.ObjectState state = dbContext.GetState( newCar );
}
Using dbContext As New EntitiesModel()
 Dim newCar As Car = dbContext.Cars.FirstOrDefault()
 newCar.Make = "NewMake"
 Dim state As Telerik.OpenAccess.ObjectState = dbContext.GetState(newCar)
End Using

The ObjectState result can have the following values:

  • Clean - the property is not modified.
  • Dirty - the property is modified.
  • NotLoaded - the property is not loaded from the database.
  • New - when you initialize a new instance and add it to the context, all properties are in state New.
  • Deleted - when you pass an existing category to the Delete method of the context, all properties are in state Deleted.
  • Detached - the object is detached from the context.