How can I set the default value of a boolean to false in Entity Framework in .NET Core.
Thank you
public class CategoryVM
{
public CategoryVM()
{
isOpen = false;
Products = new List<ProductVM>();
}
public Guid Id { get; set; }
public string? Title { get; set; }
[NotMapped]
public IFormFile? ImageFile { get; set; }
public string? catImeage { get; set; }
public Boolean isOpen { get; set; }
public virtual IEnumerable<ProductVM> Products { get; set; }
}
CodePudding user response:
Boolean properties default to false by default in C#. The json you see in swagger is just an example of the values you can pass in the request body (like it says right above the json).
CodePudding user response:
Try public Boolean isOpen { get; set; } = true; //true or false default
or in migration
public override void Up()
{
AddColumn("dbo.TABLE", "isOpen", c => c.Boolean(nullable: false,
defaultValue: true));
}