Skip to content

Blazor ViewModel with ManagedObjectLifetime save issue #4026

@russblair

Description

@russblair

Issue
When a business object is changed and saved any subsequent change that is undone will revert to the original fetched value not the last saved value.
Steps to reproduce:

  1. Using the Blazor ViewModel with the ManageObjectLifetime set to true
  2. Call the ViewModel RefreshAsync to Fetch an EditableRoot model
  3. Make a change to a property
  4. Save the model
  5. Make a second change to a property
  6. Cancel the change
  7. Note that the model property has reverted to the original value and not the value after the save in step 4

Version and Platform
CSLA version: 7.x
OS: Windows
Platform: Blazor

Problems

  1. We discovered that the ViewModel code performs the ApplyEdit on the clone and not on the model.
  2. Since the OnModelChanging is not called because the references are the same, the BeginEdit is not called.

Solution

  1. Created unit test SaveThenCancel_ValidatePropertyValue to reproduce the issue
  2. We moved the ApplyEdit from after the clone to before the clone so that it is applied to the model.
  3. Added logic to the finally block of the save to call BeginEdit if the ManagedObjectLifetime is true and the EditLevel is zero.
  4. SaveThenCancel_ValidatePropertyValue unit test now passes

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions