thejdah
thejdah

Reputation: 345

SQL Server default values

I have an app that uses a Web API to connect to a server. One of the columns, IsActive, is set to a default value of true or 1. The column defined as a bit datatype.

When I make an entry into the table using SQL Server, IsActive is set to 1. If I make the entry using Postman or the app, the value of IsActive is set to 0.

My questions are:

  1. Are default values only for entries made using SQL Server?
  2. If I want a default value placed into the table, in this scenario do I need to program the API to do this? Or can I rely on SQL Server to do it?

Upvotes: 0

Views: 256

Answers (1)

Prodigal Techie
Prodigal Techie

Reputation: 188

Looks like what @Dai commented answers your first question that it's likely a limitation of entity framework in your WebApi that is causing the issue.

To answer your second question.

If you have a model with the property public bool IsActive, that you want to default to true then you will need to make sure you assign IsActive = true before saving the record. Otherwise your API is passing false by default to the database.

Upvotes: 2

Related Questions