public static void PopulateNavigationPropertyValidations(MemberInfo member, NavigationProperty navigationProperty) { var displayName = navigationProperty.GetDisplayName() ?? navigationProperty.Name; var dataAnnotations = member.GetCustomAttributes <ValidationAttribute>(); foreach (var att in dataAnnotations) { string msg = null; var rmsg = att.ErrorMessageResourceName; if (!string.IsNullOrEmpty(att.ErrorMessageResourceName) || !string.IsNullOrEmpty(att.ErrorMessage)) { try { msg = att.FormatErrorMessage(displayName); } catch { } } if (att is MaxLengthAttribute mal && mal.Length > 0) { navigationProperty.Validators.Add(Validator.MaxLength(msg, rmsg, mal.Length)); }