Skip to content

feat: support auto-generated primary keys with IDENTITY columns#503

Merged
olavloite merged 2 commits intomainfrom
auto-generated-primary-keys
Mar 10, 2025
Merged

feat: support auto-generated primary keys with IDENTITY columns#503
olavloite merged 2 commits intomainfrom
auto-generated-primary-keys

Conversation

@olavloite
Copy link
Collaborator

@olavloite olavloite commented Mar 7, 2025

Adds support for auto-generated primary keys using IDENTITY columns. Standard primary key columns in Entity Framework are translated to GENERATED BY DEFAULT AS IDENTITY (BIT_REVERSED_POSITIVE) for Spanner.

The methods added in SpannerModelBuilderExtensions can be used to configure the strategy for generating primary keys:

SpannerModelBuilderExtensions.DisableIdentityColumns() disables the use of IDENTITY for primary keys.

SpannerModelBuilderExtensions.UseAutoIncrement() configures the Entity Framework provider to generate AUTO_INCREMENT columns instead of a GENERATED BY DEFAULT clause. This can only be used if the database has a default_sequence_kind option set.

The SpannerModelExtensions.SetIdentityOptions method can be used to manually configure the generation strategy. This can be used to set a custom sequence kind.

cc @hengfengli

Adds support for auto-generated primary keys using IDENTITY columns.
Standard primary key columns in Entity Framework are translated to
`GENERATED BY DEFAULT AS IDENTITY (BIT_REVERSED_POSITIVE)` for Spanner.

The methods added in SpannerModelBuilderExtensions can be used to
configure the strategy for generating primary keys:

`SpannerModelBuilderExtensions.DisableIdentityColumns()` disables the use
of IDENTITY for primary keys.

`SpannerModelBuilderExtensions.UseAutoIncrement()` configures the Entity
Framework provider to generate `AUTO_INCREMENT` columns instead of a
`GENERATED BY DEFAULT` clause. This can only be used if the database has
a `default_sequence_kind` option set.

The `SpannerModelExtensions.SetIdentityOptions` method can be used to
manually configure the generation strategy. This can be used to set a
custom sequence kind.
@olavloite olavloite force-pushed the auto-generated-primary-keys branch from 7a36f0a to 724ecd5 Compare March 7, 2025 15:19
@olavloite olavloite merged commit b3a9570 into main Mar 10, 2025
7 checks passed
@olavloite olavloite deleted the auto-generated-primary-keys branch March 10, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant