C# 流畅的验证和数据注释-所需数据的问题

C# 流畅的验证和数据注释-所需数据的问题,c#,validation,asp.net-mvc-5,data-annotations,C#,Validation,Asp.net Mvc 5,Data Annotations,我有一个原型MVC5项目 在这个项目中,我有一个名为Post的模型: [FluentValidation.Attributes.Validator(typeof(PostValidator))] public class Post { public int PostId { get; set; } [Required] [Display(Name="Title",ResourceType=typeof(PostResource))] public string T

我有一个原型MVC5项目

在这个项目中,我有一个名为Post的模型:

[FluentValidation.Attributes.Validator(typeof(PostValidator))]
public class Post
{
    public int PostId { get; set; }
    [Required]
    [Display(Name="Title",ResourceType=typeof(PostResource))]
    public string Title { get; set; }
    [Required]
    [Display(Name = "Content", ResourceType = typeof(PostResource))]
    public string Content { get; set; }
后验证器:

public class PostValidator : AbstractValidator<Post>
{
    public PostValidator()
    {
        RuleFor(post => post.Title).NotNull();
        RuleFor(post => post.Content).NotNull();
    }
}
这是我的问题:

我想使标题和内容不为空。即使数据库管理器去那里并输入一个空值,他也不能。这是通过
[Required]
数据注释实现的,使其
nullable=false


但是如果我不能将它与FluentValidation结合使用,我如何解决这个问题而不必到处进行迁移。

你能发布你的PostValidator吗?使用Validator更新我使用FluentApi将nullable=false字段添加到表中。但我真的不认为这是好代码。只需每次添加。如果有机会不必为单个必填字段编写FluentAPI代码,我很乐意看到它
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required