abp icon indicating copy to clipboard operation
abp copied to clipboard

Guidance Needed for Changing Primary Key from Guid to Long in ABP Framework Pre-built Features

Open asammad48 opened this issue 1 year ago • 3 comments

We are facing challenges in changing the primary key from Guid to long in ABP's pre-built features, such as User Management and Roles Management. We are planning to use the ABP Framework with an existing database. Although we have attempted several approaches, including extending the AbpUser class and overriding the primary key, these methods have not been successful. We also tried customizing the ABP User and Identity modules, but this requires extensive code modifications.

Could you please suggest an effective way to change the primary key from Guid to long in these pre-built features, so we can utilize ABP's Identity Management and Feature Management seamlessly?

Thank you.

asammad48 avatar Aug 19 '24 10:08 asammad48

Unable to create a 'DbContext' of type ''. The exception 'Unable to determine the relationship represented by navigation 'AppUser.CreatorUser' of type 'AppUser'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

I am getting this error. When adding a migration

asammad48 avatar Aug 19 '24 12:08 asammad48

` base.OnModelCreating(builder);

    /* Include modules to your migration db context */

    builder.Entity<AppUser>(b =>
    {
        b.ToTable("AbpUsers");
        b.ConfigureByConvention();
        b.HasOne<IdentityUser>().WithOne().HasForeignKey<AppUser>(x => x.Id);
    });


    builder.ConfigurePermissionManagement();
    builder.ConfigureSettingManagement();
    builder.ConfigureBackgroundJobs();
    builder.ConfigureAuditLogging();
    builder.ConfigureIdentity();
    builder.ConfigureOpenIddict();
    builder.ConfigureFeatureManagement();
    builder.ConfigureTenantManagement();`
    

  

public class AppUser : AbpUser<AppUser> { public override long Id { get; set; } public long ExistingDbID { get; set; } public string Title { get; protected set; } = "";

public int Reputation { get; protected set; }

}

asammad48 avatar Aug 19 '24 12:08 asammad48

Any updates? We are facing the same problem that uses the ABP Framework with an existing database

mackwan84 avatar Sep 24 '24 02:09 mackwan84

Excuse me, have you found a suitable solution?

NickCc6 avatar Apr 02 '25 03:04 NickCc6

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 27 '25 01:06 stale[bot]