0

I am sorry for making probably a duplicate question, but for some reason I am having a hard time finding answer for my question

How to mark entity's property to always have value while it is non-nullable?

Example:

public class ExampleEntity
{
    // How to mark that this column cannot be a default decimal value?
    [Required]
    public decimal Amount { get; set; }
}

The column definition in generated EF migration looks like this:

...
Amount = table.Column<decimal>(type: "numeric", nullable: false)
...

This is still allowing me to pass 0 as a value for this column. How to disallow this?

P.S.: I am using PostgreSQL

  • 2
    https://stackoverflow.com/questions/43426175/entity-framework-core-doesnt-validate-data-when-saving - https://github.com/dotnet/efcore/issues/5224 – Rand Random Sep 14 '21 at 12:54
  • We do this with FluentValidation and plug it in as middleware. – Fildor Sep 14 '21 at 13:02

0 Answers0