I have a nested collection property in my object. i need to make it stop on first failure for collection items. I mean error message should not be repetitive for each item for failures. Cascade is not works for this scenario. Thanks :)
My Object:
public class Customer{
public string CustomerName{get;set;}
public List<Order> Orders {get;set;}
}
public class Order{
public string OrderNumber{get;set;}
public int Amount{get;set;}
}
Example Request:
{
CustomerName="test",
Orders:[
{
"OrderNumber":null,
"Amount":0
},
{
"OrderNumber":"",
"Amount":null
},
{
"OrderNumber":"12345",
"Amount":0
}
]
}
I use fluent validation for nested object like below. But when it runs the error messages are repetitive. It should be stop on first items failure.
Code:
this.RuleForEach(x => x.Orders).Cascade(CascadeMode = CascadeMode.Stop).SetValidator(new ShipmentListRequestItemValidator()));
Error output (actual):
"OrderNumber is null!", "OrderNumber is empty!", "Amount should be greater than 0"
Error output (should be):
"OrderNumber is null!"