linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
462 stars 38 forks source link

ValueGeneratedOnAdd incorrectly mapped as Identity column #129

Closed npbenjohnson closed 2 weeks ago

npbenjohnson commented 3 years ago

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

MaceWindu commented 2 weeks ago

Not reproduced https://github.com/linq2db/linq2db/pull/4616/commits/45b869b5a65f21e89eb05cfeb17e4f215cb8ed03

Please reopen if you have more details