linq2db.EntityFrameworkCore icon indicating copy to clipboard operation
linq2db.EntityFrameworkCore copied to clipboard

ValueGeneratedOnAdd incorrectly mapped as Identity column

Open npbenjohnson opened this issue 4 years ago • 0 comments

When a column is "ValueGeneratedOnAdd", it appears that linqtodb maps it as an identity column by default, but I believe it should instead be using [columnmetadata].GetValueGenerationStrategy() == SqlServerValueGenerationStrategy.IdentityColumn to determine if the column is an identity column.

modelBuilder statement:

var pendingChangesCompanyKey = modelBuilder.Entity<ProductPrice>().Property(x => x.PendingChangesCompanyKey);
pendingChangesCompanyKey.HasComputedColumnSql($"ISNULL({nameof(ProductPrice.PendingChangesCompanyId)}, -1) PERSISTED").ValueGeneratedOnAdd();

linqtodb call:

var mergeTable = await Db.CreateLinqToDbConnection().CreateTempTableAsync<ProductPrice>("ProductPriceMerge", changedPrices);

generated sql:

CREATE TABLE [inventory].[#ProductPriceMerge]
(
	[PriceCatalogId]           int            NOT NULL,
	[StartDateUtc]             datetime2          NULL,
	[EndDateUtc]               datetime2          NULL,
	[IsFixedPrice]             bit            NOT NULL,
	[BusinessCustomerId]       int                NULL,
	[PendingChangesCompanyId]  int                NULL,
	[PendingChangesCompanyKey] int            NOT NULL IDENTITY,
	[Psin]                     int            NOT NULL,
	[AcquisitionCost]          decimal(18,2)  NOT NULL,
	[ListPrice]                decimal(18,2)  NOT NULL,
	[SalePrice]                decimal(18,2)  NOT NULL,
	[OverbillingPrice]         decimal(18,2)  NOT NULL,
	[PriceEngineLog]           nvarchar(max)      NULL,

	CONSTRAINT [PK_ProductPriceMerge] PRIMARY KEY CLUSTERED ([PendingChangesCompanyKey], [Psin], [PriceCatalogId])
)

linqtodb version 3.10.0

npbenjohnson avatar Mar 30 '21 02:03 npbenjohnson