Sync tables with GENERATE ALWAYS property
See original GitHub issueI am trying to sync 2 database with this table
CREATE TABLE [dbo].[User](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[Username] [varchar](100) NULL,
[FirstName] [nvarchar](100) NOT NULL,
[LastName] [nvarchar](100) NOT NULL,
[Emailaddress] [varchar](100) NOT NULL,
[AuditAt] [datetime2](7) GENERATED ALWAYS AS ROW START NOT NULL,
[AuditTo] [datetime2](7) GENERATED ALWAYS AS ROW END NOT NULL,
[VeritasTemplateId] [int] NULL,
CONSTRAINT [PKUser_UserId] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
CONSTRAINT [UKUser_Username] UNIQUE NONCLUSTERED
(
[Username] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
PERIOD FOR SYSTEM_TIME ([AuditAt], [AuditTo])
) ON [PRIMARY]
WITH
(
SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[UserHistory])
)
And I am running this code after SaveChangesAsync()
foreach (var entry in ChangeTracker.Entries().ToList())
{
var attribute = Attribute.GetCustomAttribute(entry.Entity.GetType(), typeof(SyncEntityAttribute));
if (attribute == null) continue;
try
{
var modelName = entry.Entity.GetType().Name;
SqlSyncProvider gatewayProvider = new SqlSyncProvider(config.GetSection("ConnectionStrings").GetSection("DefaultConnection").Value);
SqlSyncProvider stagingProvider = new SqlSyncProvider(config.GetSection("ConnectionStrings").GetSection("StagingConnection").Value);
var setup = new SyncSetup(modelName);
SyncAgent agent = new SyncAgent(stagingProvider, gatewayProvider);
var syncContext = await agent.SynchronizeAsync(setup);
}
catch (Exception ex)
{
var t = ex.Message;
}
}
But when executing agent.SynchronizeAsync(), it will throw an exception:
Cannot insert an explicit value into a GENERATED ALWAYS column in table 'dbo.User'. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column.
Is there a way to ignore or filter the properties that are GENERATE ALWAYS or temporal tables? I don’t want to set which property I am going to sync as I am doing this also for other entities (but not all).
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
4.4.1 Examples of Synchronizing
Example 4-4 Synchronizing Graphs Using CREATE PROPERTY GRAPH Statement ... CREATE TABLE persons ( person_id NUMBER GENERATED ALWAYS AS IDENTITY (START WITH ...
Read more >Auto increment even and odd for two databases ...
Here is a very simple solution, but it will work only for two servers. It can't be easily extended for more servers.
Read more >How to keep a table in sync with a view - SQL Server Forums
To create a job go to Object Explorer | <your server> | sql server Agent | Jobs. right click "jobs" and select "new...
Read more >Enable edits on sync tables - Coda Pack SDK
Sync tables allow you to pull in data from external applications and sources, but by default these tables are read-only. You can make...
Read more >Add sync tables - Coda Pack SDK
Create tables of data that automatically sync in records from an external data source. ... Properties of the schema designated as featuredProperties are ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

DMSis agnostic to the database engine, because it should work with SQL Server, MySql, SQLite, MariaDB (and sooner or later Oracle, PostgreSQL)That means it can’t work with specific features, like the great Temporal Tables option from SQL Server.
That being said, what you can do, maybe, is to remove the temporal columns ([AuditAt] and [AuditTo]) from the Setup instance from your config. And be sure you don’t let DMS creates the client table for you
Here is the script I’ve used:
And the code, where I specify the columns to sync:
That’s being said, the history table will NOT be updated on the client if you are making multiple changes on a row, between 2 syncs.
You can use DropAllAsync is you dont know how to remove DMS metadata manually