The data I work with can be added from different interfaces. So in my MVC application I need to validate that the data read from the database is correct according to the rules/attribute I sat in my model. Depending on the validation send t开发者_开发百科he user to different Views.
I need to do this validation on the SERVER-SIDE
var myModelClassObj = myDbContextInheritedModelClass.theDbSetClassMapToModel.Find(123);
// How do i validat this
The DbContext
class has a protected ValidateEntity method. You can call that method to validate your entity.
public class myDbContextInheritedModelClass : DbContext
{
public DbEntityValidationResult Validate(object entity)
{
return ValidateEntity(Entry(entity));
}
}
Then
var myModelClassObj = myDbContextInheritedModelClass
.theDbSetClassMapToModel.Find(123);
var validationResult = myDbContextInheritedModelClass.Validate(myModelClassObj);
精彩评论