How can I check that entity itself exists before executing Update or Delete?
I tried using something like the code below, but getting an error "Property name must be specified". How to implement such logic?
public CustomValidator()
{
RuleFor(x=>x).Must(ExistsInDatabase).WithMessage("Attempt to work with nonexistent entity");
}
private bool ExistsInDatabase(MyClass myClassInstance)
{
if (myClassInstance == null)
return false;
return true;
}
UPDATE: the question concerns the syntax in RuleFor() - is it possible to use (x=>x) without specifying particular property? or somehow else to check state of the whole entity being validated?