I have columns on a MSSQL table that are the temporal start and end times. Here is the SQL column creation.
[TemporalStartTime] [datetime2](7) GENERATED ALWAYS AS ROW START NOT NULL,
[TemporalEndTime] [datetime2](7) GENERATED ALWAYS AS ROW END NOT NULL,
When generating a database-first model in Entity Developer these columns are not be marked with the 'Value Generated' property as 'OnAdd' or 'OnAddOrUpdate' in the model like it does for PK columns. I also vaguely remember this working in the past.
Is this a known issue?
Entity Developer Version: 6.11.1219
Target Framework: .NET Framework
EF Core 3.1.14
GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model
Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model
Thank you for your report. We have reproduced the issue and are investigating it. We will notify you about the result.
Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model
Detection of GENERATED ALWAYS AS ROW START and GENERATED ALWAYS AS ROW END columns in SQL Server 2016 and higher by Create Model Wizard / Update From Database Wizard is implemented in Entity Developer v6.11.1258: viewtopic.php?f=32&t=46740.
Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model
In v6.11.1258 it does appear to be working correctly but then the fix seems to have been reverted in the latest version (i.e. v6.11.1283).
To summarize:
Here are some examples
ALTER TABLE [dbo].[Contact] ADD DEFAULT (newid()) FOR [ID]
ALTER TABLE [dbo].[Contact] ADD DEFAULT ((1)) FOR [IsEnabled]
ALTER TABLE [dbo].[Contact] ADD DEFAULT (getdate()) FOR [CreatedDate]
These examples generated correctly with ValueGeneratedOnAdd().HasDefaultValueSql("...") previous to v6.11.1258.
In v6.11.1258 they were all generated with ValueGeneratedNever().
In v6.11.1283 all but the GUID column generated correctly. The GUID column still generated with ValueGeneratedNever().
To summarize:
- Before and after v6.11.1258: If the GENERATED ALWAYS column had a default value it generates with ValueGeneratedOnAdd and if the column did not have a default value it generated with ValueGeneratedNever.
- In v6.11.1258: The GENERATED ALWAYS column always generated correctly with ValueGeneratedOnAddOrUpdate.
Here are some examples
ALTER TABLE [dbo].[Contact] ADD DEFAULT (newid()) FOR [ID]
ALTER TABLE [dbo].[Contact] ADD DEFAULT ((1)) FOR [IsEnabled]
ALTER TABLE [dbo].[Contact] ADD DEFAULT (getdate()) FOR [CreatedDate]
These examples generated correctly with ValueGeneratedOnAdd().HasDefaultValueSql("...") previous to v6.11.1258.
In v6.11.1258 they were all generated with ValueGeneratedNever().
In v6.11.1283 all but the GUID column generated correctly. The GUID column still generated with ValueGeneratedNever().
Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model
We investigated further (by creating a brand new model in the latest version) and discovered that the behavior in the latest version is correct unless the GENERATED ALWAYS column has a default value. If the GENERATED ALWAYS column has a default value should it still generate with ValueGeneratedOnAddOrUpdate?
Recreating the model fixed all of the other default value issues we were seeing so that part of my previous post can be ignored.
Recreating the model fixed all of the other default value issues we were seeing so that part of my previous post can be ignored.