Retrieving Members Based On Their State
Sometimes it can be useful to find exactly which properties for a given entity have been changed. The OpenAccessContext class exposes the GetMemberNames method, which returns a collection of members' names for a given instance based on the provided member state.
using (FluentModel dbContext = new FluentModel())
{
Category category = dbContext.Categories.FirstOrDefault();
category.CategoryName = "New Category Name";
IEnumerable<string> modifiedMembers = dbContext.GetMemberNames(category,
Telerik.OpenAccess.ObjectState.Dirty);
}
Using dbContext As New FluentModel()
Dim _category As Category = dbContext.Categories.FirstOrDefault()
_category.CategoryName = "New Category Name"
Dim modifiedMembers As IEnumerable(Of String) = dbContext.GetMemberNames(_category,
Telerik.OpenAccess.ObjectState.Dirty)
End Using
The ObjectState argument 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.