protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value != null) { BarShowroomDb _db = new BarShowroomDb(); try { Bar bar = _db.Bars.Single(s => s.Name == value); } catch (Exception ex) { if (_db != null) { _db.Dispose(); } if (!m_bExists) { return(ValidationResult.Success); } return(new ValidationResult(FormatErrorMessage(validationContext.DisplayName))); } if (_db != null) { _db.Dispose(); } if (m_bExists) { return(ValidationResult.Success); } return(new ValidationResult(FormatErrorMessage(validationContext.DisplayName))); } return(new ValidationResult(FormatErrorMessage(validationContext.DisplayName))); }