andrewlock / StronglyTypedId

A Rosyln-powered generator for strongly-typed IDs
MIT License
1.52k stars 79 forks source link

Work around for UseIdentityColumn? #35

Closed drewdelano closed 3 years ago

drewdelano commented 3 years ago

It looks like there's a bug in EF that prevents it from recognizing strongly typed IDs (longs / int64) as potential identity columns.

Identity value generation cannot be used for the property 'Id' on entity type 'MyTask' because the property type is 'TaskId'. Identity value generation can only be used with signed integer properties.

Has anyone found a way to avoid this? I'd put this in the EF Core repo, but I'm guessing it wouldn't be prioritized.

drewdelano commented 3 years ago

This seemed to work for me: https://github.com/SpatialFocus/EFIdentityColumnWithValueConverterWorkaround

MovGP0 commented 2 years ago

Is there also a version of that workaround for SQL Server?

MovGP0 commented 2 years ago

The following does not work :-(

        modelBuilder.Entity<Customer>(entity =>
        {
            entity.ToTable("Customer", "dbo");
            entity.HasKey(e => e.Id);

            entity.Property(e => e.Id)
                .HasColumnName("Id")
                .HasColumnType("bigint")
                .HasConversion<CustomerId.EfCoreValueConverter>()
                .ValueGeneratedOnAdd();

            // ...
        });