Efcore: EF Core 210 not including columns with default values in insert into query

Created on 4 Sep 2018  路  2Comments  路  Source: dotnet/efcore

Yes I know this looks like a duplicate from earlier versions of EF core, but it is clearly (to me at least) a bug.

If you have a SQL column of type bit having a default value of true and you model it in EF as a bool and configure the property in code-first with .HasDefaultValue(true), the when you add a new instance o the entity the generated SQL ignores a vale of false in the class instance supplied. It is incorrectly comparing the value to the CLR default value and deciding there is no need to explicitly set the value to false.

It should be comparing the value to the MODEL DEFAULT not the clr and realising that it does indeed need to include the property in the generated SQL.

closed-question customer-reported

Most helpful comment

@martin-kelley We're not going to change this for 2.2, but we discussed in triage and I have opened #13224 to look at making this a better experience. Using the model default in some way may be something we could consider.

All 2 comments

@martin-kelley We're not going to change this for 2.2, but we discussed in triage and I have opened #13224 to look at making this a better experience. Using the model default in some way may be something we could consider.

I got bitten by the exact same problem too. This behaviour is really astonishing.

Was this page helpful?
0 / 5 - 0 ratings