Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Validation on complex entity #349


User avatar
0
omital created

Hi, Suppose we have entities like this

public class DocHeader : Entity
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public virtual ICollection<DocDetail> DocDetails { get; set; }
    }

    public class DocDetail
    {
        public int Id { get; set; }
        public byte Type { get; set; }
        public int DocHeaderId { get; set; }
        public int Value { get; set; }
        [ForeignKey("DocHeaderId")]
        public virtual DocHeader DocHeader { get; set; }

    }

we have specific validation in Update method in DocHeaderApplicationService and want to validate based on details for current docheader. for example 1- value summaries in doc detail not to be grater than 30 2- user cant select detail with same [type] in DocHeader

how can I do this: 1- validate detail (this is not [â—¦Validating data transfer objects] this is [Validating Entity]) 2-passing validation erros to client 3-Where I place validation ? DomainService or in ApplicationService


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Answers for your some questions can be found on the forum, please search it after reading my answer.

    First of all, you should add data annotations (like [Required] or/and [StringLength(30)]) to your properties. This provides database level validation. Also, add same to application service DTOs to basic data validation. If you have custom amd complex validation logic beside these simple validations, you can make it in a Domain Service. Do not make domain logic validation in app services because an app service method is for single use case and your entities can be updated in another use case.