GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
nruffing
Posts: 4
Joined: Fri 21 May 2021 13:24

GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Post by nruffing » Fri 21 May 2021 13:41

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Post by Shalex » Sat 22 May 2021 09:49

Thank you for your report. We have reproduced the issue and are investigating it. We will notify you about the result.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Post by Shalex » Mon 07 Jun 2021 15:48

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.

nruffing
Posts: 4
Joined: Fri 21 May 2021 13:24

Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Post by nruffing » Tue 13 Jul 2021 18:44

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:
  • 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.
Also in v6.11.1258 we noticed some issues with default values.

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().

nruffing
Posts: 4
Joined: Fri 21 May 2021 13:24

Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Post by nruffing » Tue 13 Jul 2021 19:30

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: GENERATED ALWAYS AS ROW START on MSSQL Column Not Mapping to Generated on EF Core Model

Post by Shalex » Mon 19 Jul 2021 08:53

nruffing wrote: Tue 13 Jul 2021 19:30 If the GENERATED ALWAYS column has a default value should it still generate with ValueGeneratedOnAddOrUpdate?
Yes, it should. We consider the current behavior is correct.

Post Reply