首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用fluent validation验证类的另一个IEnumerable中的类的IEnumerable

如何使用fluent validation验证类的另一个IEnumerable中的类的IEnumerable
EN

Stack Overflow用户
提问于 2020-04-13 16:44:34
回答 1查看 75关注 0票数 0

我有这些课程

代码语言:javascript
复制
public class CryptocurrencyDto
{
    public int RequestId { get; set; }
    public IEnumerable<Cryptocurrency> Cryptocurrencies { get; set; }
}

public class Cryptocurrency : BaseClass
{
    public string Ticker { get; set; }
    public string Name { get; set; }
    public double TotalSupply { get; set; }
    public double CirculatingSupply { get; set; }
    public IEnumerable<Note> Notes { get; set; }
}

public class Note
{
    public int NoteId { get; set; }
    public string Description { get; set; }
    public IEnumerable<Url> Urls { get; set; }
    public byte Image { get; set; }
    public int DisplayOrder { get; set; }
}

public class Url
{
    public string UrlId { get; set; }
    public string Link { get; set; }
    public string Description { get; set; }
}

我有这个端点

代码语言:javascript
复制
    [HttpPost]
    public void Post([FromBody] CryptocurrencyDto cryptocurrency)
    {

    }

如何通过这些类进行验证?到目前为止,我只知道如何验证第一个类CryptocurrencyDto。我不知道怎样才能到达其他班级。加密货币、笔记和Url。

EN

回答 1

Stack Overflow用户

发布于 2020-04-13 18:18:19

当您将FluentValidation添加到问题标签时,这是使用FluentValidation的Collection Validation

代码语言:javascript
复制
public class CryptocurrencyDtoValidator : AbstractValidator<CryptocurrencyDto> {
  public CryptocurrencyDtoValidator() {
    RuleForEach(x => x.Cryptocurrency).NotNull();
  }
}

More info

但还有许多其他方法可以使用关联类的验证(例如TIEnumerable<T>):

More info

  • Check:
  1. 创建并使用ValidationAttributeController级别中的任何关联类。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61184282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档