Hi,
I have added a max length attribute to my DTO. However when I create an object of DTO and assign a string more than the permissible length, it does not give me error and the error is coming only when the object is getting committed in the database.
[Required]
[MaxLength(100)]
public string Description { get; set; }
Am I doing something wrong or it is a default behavior.
3 Answer(s)
-
0
Hi @pankajmathur,
What you did is correct actually, see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Validating-Data-Transfer-Objects#DocUsingAnnotations">https://aspnetboilerplate.com/Pages/Doc ... nnotations</a>.
Can you share your dto class ?
-
0
[AutoMapTo(typeof(TaxCode))] public class CreateOrUpdateTaxCodeDto: Entity { [Required] [MaxLength(20)] public string EntityId { get; set; }
[Required] [MaxLength(100)] public string Description { get; set; } [Required] public decimal Rate { get; set; } }
-
0
Hi,
It should be defined like this:
public class CreateOrUpdateTaxCodeDto: EntityDto
Can you try it like that and see if it works ?