-3
One or more validation errors were detected during model generation:
Sigma.Infra.Data.Context.ValidationResult: : EntityType 'ValidationResult' has no key defined. Define the key for this EntityType.
Sigma.Infra.Data.Context.ValidationFailure: : EntityType 'ValidationFailure' has no key defined. Define the key for this EntityType.
ValidationResult: EntityType: EntitySet 'ValidationResult' is based on type 'ValidationResult' that has no keys defined.
ValidationFailures: EntityType: EntitySet 'ValidationFailures' is based on type 'ValidationFailure' that has no keys defined.
Class where Validationresult is, but cannot be changed
#region Assembly FluentValidation, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=7de548da2fbae0f0
//
#endregion
using FluentValidation.Results;
using System.Collections.Generic;
namespace FluentValidation.Results
{
// Summary:
// The result of running a validator
public class ValidationResult
{
//
// Summary:
// Creates a new validationResult
public ValidationResult();
//
// Summary:
// Creates a new ValidationResult from a collection of failures
//
// Parameters:
// failures:
// List of FluentValidation.Results.ValidationFailure which is later available through
// FluentValidation.Results.ValidationResult.Errors. This list get's copied.
//
// Remarks:
// Every caller is responsible for not adding null to the list.
public ValidationResult(IEnumerable<ValidationFailure> failures);
//
// Summary:
// Whether validation succeeded
public virtual bool IsValid { get; }
//
// Summary:
// A collection of errors
public IList<ValidationFailure> Errors { get; }
public string[] RuleSetsExecuted { get; }
//
// Summary:
// Generates a string representation of the error messages separated by new lines.
public override string ToString();
//
// Summary:
// Generates a string representation of the error messages separated by the specified
// character.
//
// Parameters:
// separator:
// The character to separate the error messages.
public string ToString(string separator);
}
}
Class of Iselfvalidation
using FluentValidation.Results;
namespace Sigma.Domain.Interfaces{
/// <summary>
/// Api de validação
/// https://fluentvalidation.net
/// </summary>
///
public interface ISelfValidation
{
ValidationResult GetValidationResult();
bool IsValid { get; }
}
}
This is the entity and the method that appears in the error is inside Iselfvalidation
public class ParametroArea : ISelfValidation
{
public ParametroArea(){
objID=Guid.NewGuid();
}
public Guid objID { get; set; }
public Guid IDAreaServico { get; set; }
public Guid IDUltimaCultura { get; set; }
public string areaArrendada { get; set; }
public string tempoRestante { get; set; }
public string condicaoAtual { get; set; }
public string observacaoComplementar { get; set; }
[JsonIgnore]
public virtual AreaServico AreaServico { get; set; }
[JsonIgnore]
public virtual Cultura Cultura { get; set; }
private ValidationResult validationResult;
public ValidationResult GetValidationResult()
{
return validationResult;
}
private void SetValidationResult(ValidationResult value)
{
validationResult = value;
}
public bool IsValid
{
get
{
var validador = new ParametroAreaValidation();
this.SetValidationResult(validador.Validate(this));
return GetValidationResult().IsValid;
}
}
}
}
And the entity
ValidationResult
has a primary key?– Leandro Angelo
Can put the code of your entity ?
– Matheus
@Leandroangelo No, she has no primary key
– Jcsmz
@Matheus I can do it
– Jcsmz