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

The create of a new row in the database uses CrudServices's CreateAndSave method. The RazorAppPage application contains two examples of the use of the CreateAndSave method:

Notes

  1. GenericServices has any constructors or static methods it will try to find one that fits. Otherwise it tries to use AutoMapper.
  2. If there are ctor/static methods in the entity it will try to match the DTOs name, (minus a set of possible DTO endings) with a ctor/static 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/ctor/AutoMapper you want to use, by providing a second parameter to the command, e.g. _service.CreateAndSave(Data, "ctor"). This is useful if there are multiple methods that will match the DTO non-read-only properties. The options for the second parameter are:
    • ctor - any constructor
    • ctor(n) - a constructor with n parameters, e.g. "ctor(4)"
    • staticMethodName - use a specific named static method, e.g. "CreateBook"
    • staticMethodName(n) - use a specific named static method with n parameters, e.g. "CreateBook(5)"
    • AutoMapper - use AutoMapper's save mapping to copy the DTO into the entity
  4. GenericServices only looks for static methods that return IStatusGeneric<TEntity> for a create. The difference between using a static method over a constructor is that the static method can return a status, with errors or a success message.
You can’t perform that action at this time.