question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF Core 1.0 not including columns with default values in insert into query

See original GitHub issue

Steps to reproduce

I’m using EF Core 1.0 and I have a model where I design some properties with default values similar to modelBuilder.Entity<Listings>(entity => { entity.Property(e => e.IsActive).HasDefaultValueSql("1");} The table in the database is created correctly defining the columns with the corresponding default value [IsActive] bit NOT NULL DEFAULT 1

The issue

When I add a new entity and save changes in my context, the insert into statement generated does not contain the properties that have default values even though I assign specific values for those properties. The result in the database is a record where the columns with default values doesn’t contain the values I passed in my model.

More info on this post http://stackoverflow.com/questions/40619319/entity-framework-not-including-columns-with-default-value-in-insert-into-query/

Further technical details

EF Core version: 1.0 Visual Studio version: VS 2015

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:69 (22 by maintainers)

github_iconTop GitHub Comments

16reactions
hisuwhcommented, Nov 2, 2018

Just want to weigh in as this issue has just stung us. Unsure why it has been closed. We have the same scenario - added a default value of true to a boolean property so that when the migration was applied existing records would get the value of true.

Completely unexpected behaviour that this would make it impossible to set false when inserting a record.

13reactions
wozzocommented, Aug 9, 2021

Using V5.0.5 and this is still an issue. If it’s not possible to set a default value that is not the same as the C# default for that type then why is the method offered? We had an int property where our DB default was set to -1. With this bug it meant that any time we tried to set it to 0, it was stored in the DB as -1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework not including columns with default value ...
In the output window of VS, I see how it send all properties in an INSERT INTO query and then it does a...
Read more >
What is new in EF Core 1.0 - Entity Framework
Database generated values. Allows for values to be generated by the database on insert (default values) or update (computed columns). Sequences ...
Read more >
Generated Values - EF Core
This page details various patterns for configuration value generation with EF Core. Default values. On relational databases, a column can be ...
Read more >
Override sql default value on insert using Entity Framework ...
1.0 you can do that by setting the property to any value different than the default for the type (i.e. 0 for numbers,...
Read more >
ASP.NET Core 1.0 High Performance - Page 135 - Google Books Result
NewGuid(), as using a default column value in the DB means you have to retrieve the ID after an insert, as shown previously....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found