I am using Domain-Driven-Design have an entity called Menu, need to check if the item has up to three levels, the class is now as shown below:
public class Menu : Entity
{
public virtual AreaMenu AreaMenu { get; set; }
public virtual Menu MenuPai { get; set; }
public string Title{ get; set; }
public virtual Site Site { get; set; }
public Status Status { get; set; }
public byte StatusId
{
get { return (byte)Status; }
set { Status = (Status)value; }
}
public bool VerifyLevels()
{
if (this.MenuPai == null || this.MenuPai.MenuPai == null || this.MenuPai.MenuPai.MenuPai == null || this.MenuPai.MenuPai.MenuPai.MenuPai == null)
return true;
return false;
}
}
This check levels (public bool VerifyLevels()) , it is right to be here in the entity or is correct that it is in the repository?
Yes, it is right to put validations in your entity. On the other hand, you could call this validation from your repository Save method to validate before saving
E.g.