Skip to content

Instantly share code, notes, and snippets.

@papeMK2
Created April 27, 2020 07:23
Show Gist options
  • Save papeMK2/dba3727267b3ed7e8c608417be46e608 to your computer and use it in GitHub Desktop.
Save papeMK2/dba3727267b3ed7e8c608417be46e608 to your computer and use it in GitHub Desktop.
Custom validation with DbContext
using papemk2.Entities.Db;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace papemk2.Attributes
{
public class CustomValidationAttribute : ValidationAttribute
{
public CustomValidationAttribute()
{
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
papemk2DbContext context = (papemk2DbContext) validationContext.GetService(typeof(papemk2DbContext));
return base.IsValid(value, validationContext);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment