How to query System generated columns on Developer Edition

Zhang, Li 20 Reputation points
2024-12-23T22:26:13.1633333+00:00

We are using EF 8.0 to manage data, one of the recent challenges is that the query on SQL Server Developer Edition and Enterpise Edition returns different results.

i.e., two columns StartTime/EndTime are generated like

entity.Property(e => e.StartTime).ValueGeneratedOnAddOrUpdate();	
			

However, a rawSql (Select *) won't return those two columns on Developer Edition. My question: how to write the right query disregarding the different editions? Thanks.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
767 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,214 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 114.6K Reputation points MVP
    2024-12-24T09:42:53.2266667+00:00

    After the edit of your question, I am brave enough to make a guess of what is going on. But it is just a guess - I have to read between the lines quite a bit.

    When you say:

    However, a rawSql (Select *) won't return those two column

    That sounds like if you run

    SELECT * FROM tbl
    

    You don't see these two columns at all.

    That would be the case if the table in question is a temporal table and the period columns have the HIDDEN attribute. Compare these two:

    CREATE TABLE temporal1 (
       keycol int NOT NULL,
       datacol nvarchar(22) NOT NULL,
       starttime datetime2(3) GENERATED ALWAYS AS ROW START,
       endtime datetime2(3) GENERATED ALWAYS AS ROW END,
       PERIOD FOR SYSTEM_TIME (starttime, endtime),
       CONSTRAINT pk_temporal1 PRIMARY KEY (keycol)
    )
    WITH (SYSTEM_VERSIONING = ON)
    CREATE TABLE temporal2 (
       keycol int NOT NULL,
       datacol nvarchar(22) NOT NULL,
       starttime datetime2(3) GENERATED ALWAYS AS ROW START HIDDEN,
       endtime datetime2(3) GENERATED ALWAYS AS ROW END HIDDEN,
       PERIOD FOR SYSTEM_TIME (starttime, endtime),
       CONSTRAINT pk_temporal2 PRIMARY KEY (keycol)
    )
    WITH (SYSTEM_VERSIONING = ON)
    SELECT * FROM temporal1
    SELECT * FROM temporal2
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.