Multiple bugs happen when following the Guidance flow after adding a delete entity to the domain layer.
First bug:
Bug is situated in the SaveValidator class after adding a business class from an existing entity.
Rule for DeletedOn is making the validator crash in method ValidateAsync in ValidatorBase when inserting a new entity.
This happens because the rule is checking the value of DeletedOn, but DeletedOn is a nullable property.
Second bug(which will happen if you fix the issue above):
If you try to save an entity after fixing the issue above,
SQL will not allow you because you are trying to insert a null value into the database because DeletedBy and DeletedOn is still required in the database mapping configuration.
Third bug(or maybe a feature):
The DeleteValidator should contain the DeletedBy and DeletedOn rules described above.
Fourth bug:
UpdatedBy on the entity should also be nullable, because in the delete scenario you never set the UpdatedBy and UpdatedOn properties but they are still required in the database, also resulting in an exception.
Feature request:
Entity is not loaded before doing an update, would be nice if the entity is pre-loaded in the BL so the CreatedBy and CreatedOn values are copied from the existing entity.
To Reproduce
Steps to reproduce the behavior:
Add a delete entity to the domain layer.
Add from an existing entity business classes on the database layer.
Validators get created with all the database mapping as well.
When trying to insert a new entity through swagger, you always get a null reference exception.
Expected behaviorFirst bug:
Deleted lines should be removed(since you use a DeleteValidator when deleting an entity)
Second bug:
Make DeletedBy nullabe in the entity and make DeletedBy and DeletedOn not required in the mapping configuration.
DeletedBy should be an explicit nullable string, otherwise you get issues with the Graph object.
Third bug:
DeletedBy and DeletedOn rules should be present in the DeleteValidator
Fourth bug:
Make UpdatedBy nullabe in the entity and make UpdatedBy and UpdatedOn not required in the mapping configuration.
UpdatedBy should be an explicit nullable string, otherwise you get issues with the Graph object.
Describe the bug
Multiple bugs happen when following the Guidance flow after adding a delete entity to the domain layer.
First bug: Bug is situated in theSaveValidator class after adding a business class from an existing entity.
Rule for DeletedOn is making the validator crash in method ValidateAsync in ValidatorBase when inserting a new entity.
This happens because the rule is checking the value of DeletedOn, but DeletedOn is a nullable property.
Second bug(which will happen if you fix the issue above): If you try to save an entity after fixing the issue above, SQL will not allow you because you are trying to insert a null value into the database because DeletedBy and DeletedOn is still required in the database mapping configuration.
Third bug(or maybe a feature): TheDeleteValidator should contain the DeletedBy and DeletedOn rules described above.
Fourth bug: UpdatedBy on the entity should also be nullable, because in the delete scenario you never set the UpdatedBy and UpdatedOn properties but they are still required in the database, also resulting in an exception.
Feature request: Entity is not loaded before doing an update, would be nice if the entity is pre-loaded in the BL so the CreatedBy and CreatedOn values are copied from the existing entity.
To Reproduce Steps to reproduce the behavior:
Expected behavior First bug: Deleted lines should be removed(since you use aDeleteValidator when deleting an entity)
Second bug: Make DeletedBy nullabe in the entity and make DeletedBy and DeletedOn not required in the mapping configuration. DeletedBy should be an explicit nullable string, otherwise you get issues with the Graph object.
Third bug: DeletedBy and DeletedOn rules should be present in theDeleteValidator
Fourth bug: Make UpdatedBy nullabe in the entity and make UpdatedBy and UpdatedOn not required in the mapping configuration. UpdatedBy should be an explicit nullable string, otherwise you get issues with the Graph object.
Screenshots First bug:
Second bug:
Desktop: