Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseIdentityAlwaysColumns for custom types #3452

Open
akazik opened this issue Jan 31, 2025 · 0 comments
Open

UseIdentityAlwaysColumns for custom types #3452

akazik opened this issue Jan 31, 2025 · 0 comments

Comments

@akazik
Copy link

akazik commented Jan 31, 2025

Hi,

we use a custom type instead of long as a key.

Example:

// ID
public readonly partial record struct AddressId {
  public AddressId(long raw) {
    Raw = raw;
  }
  public long Raw { get; }
}

// Converter
public class AddressIdValueConverter : ValueConverter<AddressId, long> {
  public AddressIdValueConverter()
    : base(
      v => v.Raw,
      v => new(v)
    ) { }
}

// Registering it
   configurationBuilder
      .Properties<AddressId>()
      .HaveConversion<AddressIdValueConverter>();

// The file is actually generated out of a name and type
// and contains a lot more (like json conversion, model binder, tostring)

Which works like a charm, except that

    modelBuilder.UseIdentityAlwaysColumns();

has no effect.

Though it can be set on a per property basis:

        entity.Property(x => x.AddressId).UseIdentityAlwaysColumn();

Used versions:
Npgsql (8.0.6)
Npgsql.EntityFrameworkCore.PostgreSQL (8.0.11)
in a .net 8 project with EF 8.*

It would be great if UseIdentityAlwaysColumns could also work in this case.

@vonzshik vonzshik transferred this issue from npgsql/npgsql Feb 4, 2025
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

No branches or pull requests

1 participant