Service Stack〔Required〕Annotation不起作用



我有一个模型,我在上面添加了一个必需的注释,但它什么都不做。它不会抛出任何错误。我是否必须在配置中添加一些内容以确保激发注释。

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

[Required]属性可以在OrmLite数据模型中用于注释不可为null的字段,但它对ServiceStack DTO没有任何影响。

要验证DTO,建议使用内置的Fluent Validation支持。

最新更新