Skip to content
Jon P Smith edited this page Apr 10, 2018 · 13 revisions

The update of an entity in the database uses CrudServices's UpdateAndSave method. In web applications this has a typical two-stage update consisting of

  1. ReadSingle<EntityOrDto>(key) to show the user the current state, some of which will be editable.
  2. UpdateAndSave(Data) to update the entity.

The RazorAppPage application contains multiple examples of the use of the UpdateAndSave method:

Updates of DDD-styled entity classes

Updates of standard-styled entity classes

Notes

  1. If the entity class has any methods that return void or IStatusGeneric then it will look at these to do the update. Otherwise it tries to use AutoMapper.
  2. If there are methods in the entity it will try to match the DTOs name, (minus a set of possible DTO endings) with a method. If there is a match it will set this as the default one to use.
  3. You can state exactly what type/name of method/AutoMapper you want to use, by providing a second parameter to the command, e.g. _service.UpdateAndSave(Data, "RemovePromotion"). This is useful if there are multiple methods that will match the DTO non-read-only properties. The options for the second parameter are:
    • methodName - use a specific named static method, e.g. "AddPromotion"
    • methodName(n) - use a specific named static method with n parameters, e.g. "AddPromotion(3)"
    • AutoMapper - use AutoMapper's save mapping to copy the DTO into the entity
  4. For methods with no parameters, e.g. "RemovePromotion", you must define the method name either in the second parameter of the call, or by providing a PerDtoConfig to the DTO with the UpdateMethod overriden with the name.
Clone this wiki locally