SQL Server column default value
Posted: Thu 25 Nov 2021 20:23
Hello,
we are using MS SQL Server and EF Core 3(.1) and ED 6.12.1354.
If a column has a default value in database not matching the type of column, this is not a problem for SQL Server.
E.g. colum is nvarchar(16) and default value is 0 (integer), not '0' (nvarchar). If inserting a new row, the value for that column is set to '0'.
But ED creates that config line with 'ValueGeneratedOnAdd' instead of 'ValueGeneratedNever':
HasColumnType(@"nvarchar(16)").ValueGeneratedOnAdd().HasMaxLength(16).HasDefaultValueSql(@"0");
And does not set the property in code to "0".
I guess this is happening because of differnet types?
Is it possible to have the poperty set to the (converted) default value in the autogenerated code of the entity constructor to get rid of the ValueGeneratedOnAdd?
we are using MS SQL Server and EF Core 3(.1) and ED 6.12.1354.
If a column has a default value in database not matching the type of column, this is not a problem for SQL Server.
E.g. colum is nvarchar(16) and default value is 0 (integer), not '0' (nvarchar). If inserting a new row, the value for that column is set to '0'.
But ED creates that config line with 'ValueGeneratedOnAdd' instead of 'ValueGeneratedNever':
HasColumnType(@"nvarchar(16)").ValueGeneratedOnAdd().HasMaxLength(16).HasDefaultValueSql(@"0");
And does not set the property in code to "0".
I guess this is happening because of differnet types?
Is it possible to have the poperty set to the (converted) default value in the autogenerated code of the entity constructor to get rid of the ValueGeneratedOnAdd?