-
Notifications
You must be signed in to change notification settings - Fork 94
Create
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:
-
Pages/Home/Create - creates a DDD-styled
Book
entity by calling a static method. -
Pages/Authors/Create - creates a standard-styled
Author
entity using the AutoMapper Save mapping.
- GenericServices has any constructors or static methods it will try to find one that fits. Otherwise it tries to use AutoMapper.
- 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.
- 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
- 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.