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

Getting an Object State

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 ( FluentModel dbContext = new FluentModel() )
{
   Car newCar = dbContext.Cars.FirstOrDefault();
   newCar.Make = "NewMake";
   Telerik.OpenAccess.ObjectState state = dbContext.GetState( newCar );
}
Using dbContext As New FluentModel()
 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.