FluentValidation: Check if one of two fields are empty

后端 未结 6 665
醉话见心
醉话见心 2020-12-24 05:26

I have this model

public class Person
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName         


        
6条回答
  •  生来不讨喜
    2020-12-24 05:49

    I don't know that library, but if you just want to check those two properties for null, then you can use this:

    RuleFor(person => person.FirstName ?? person.LastName).NotNull();

    EDIT This doesn't work, because it throws an InvalidOperationException. Use Zabavsky's solution instead.

提交回复
热议问题