Blazored / FluentValidation

A library for using FluentValidation with Blazor
https://blazored.github.io/FluentValidation/
MIT License
586 stars 84 forks source link

[Bug] validating collection elements #142

Open GioviQ opened 2 years ago

GioviQ commented 2 years ago

I have the following validator:

 public class CustomerValidator : AbstractValidator<Customer> 
 {
   public CustomerValidator() 
   {
     RuleForEach(x => x.Orders).SetValidator(new OrderValidator());
   }
 }

Orders is of type https://github.com/Breeze/breeze.sharp/blob/master/Breeze.Sharp/INavigationSet.cs#L60

This line https://github.com/Blazored/FluentValidation/blob/main/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs#L171 gives Ambiguos Match Exception

The escamotage is creating and using a derived property like List<Order> OrderList { get => Orders.ToList() } , but I would like not to use it.

Sharaf-Mansour commented 2 years ago

@GioviQ Can you provide a minimal repo to test this implementation and share more details about the Exception?

GioviQ commented 2 years ago

@Sharaf-Mansour I think it is very clear that item property is not found, have you click on the link pointing to the exact line of code where the issue is?

Sharaf-Mansour commented 2 years ago

@GioviQ Yes I have seen it, but it says This code assumes C# conventions (one indexer named Item with one param) and if it is not found it will return null which is checked in the line after. I needed more details like the exception msg and mini repo to interstage the issue further so I can assist.

GioviQ commented 2 years ago

@Sharaf-Mansour see my PR

Liero commented 2 years ago

@GioviQ: Ideally you replicate the issue online here: https://www.telerik.com/blazor-ui/repl, so the the maintainers does not have to spent time replicating the issue.

In your particular case, it seems, the the bug is related to code you haven't posted anywhere (NotifiableCollection.cs probably?).

Anyway, I think your PR does not solve the source of the issue, see my comment

GioviQ commented 2 years ago

The PR has been tested with https://github.com/enkodellc/blazorboilerplate