服务堆栈[必需]注释不起作用

时间:2019-11-12 19:48:24

标签: c# api servicestack data-annotations

我有一个模型,并在上面添加了必需的注释,但它没有任何作用。它不会引发任何错误。我是否必须在配置中添加一些内容以确保注释被触发。

using System.ComponentModel.DataAnnotations;

 [ApiMember(Description = "The student ID to lookup", IsRequired = true, ParameterType = "form")]
 [Required]
 public int? StudentId { get; set; }

1 个答案:

答案 0 :(得分:1)

[Required]属性可以在OrmLite数据模型中用于注释不可为空的字段,但对ServiceStack DTO无效。

要验证DTO,建议使用built-in Fluent Validation support