EF Core Default Value Mapping
I have a SQL Server database with a table with bit columns that have a default value set.
When LinqPad maps these it looks like it detects the default value and then adds ValueGeneratedOnAdd to the mapping for the entity type. This blocks us from creating a new entity with something other than the default value. Is there a way to disable this? Can we adjust how LinqPad maps our table to the C# entity?
Comments
Are you referring to the following issue?
https://github.com/dotnet/efcore/issues/7089
Yeah, it sounds somewhat similar to this comment:
https://github.com/dotnet/efcore/issues/7089#issuecomment-262656974
It seems like when there is a default value defined on a column the model that gets generated by LinqPad configures that column as
ValueGeneratedOnAdd()
which assumes that the database will explicitly generate a value which causes EF to not include the value from your C# object on insert.Normally this would be fine with something like a primary key, but on a non PK bit column it would be nice to have it not add ValueGeneratedOnAdd to those columns. Is there a way to modify the EF DbContext and model that LinqPad is creating or could we possible have an option to control this behavior?
Sure. In the next build, I'll add a checkbox to achieve that behavior in the connection dialog.
That's awesome!! Thanks!!