0
私はWebAPIのセットを開発しています。 私はDataAnnotationを使用して、私のモデルを定義する場合:FluentApi IsRequiredがPostManによって無視される
public Prat()
{
public int Id { get; set; }
[Required]
[StringLength(10)]
public string Pratica { get; set; }
public int Anno { get; set; }
}
私はこのようなPOST(ポストマンを使用して)送信する場合:私はこのエラーを得た
{
"pratica": "",
"anno": 2000,
}
、期待通りの
{
"Pratica": [
"The Pratica field is required."
]
}
しかし、 、DataAnnotationの代わりにFluentApiを使用する場合:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Prat>(entity =>
{entity.Property(e => e.Pratica)
.IsRequired()
.HasColumnType("varchar(10)")}
}
検証は実行されません。 なぜですか? ありがとうございました
ありがとうグレゴリー! – skysurfer