Base solution for your next web application
Open Closed

Change All Primary Keys From Long to Guid #2100


User avatar
0
moustafa created

Hello, how can i change all primary keys from long to Guid that including all tables such as user,role,permissions,..etc


2 Answer(s)
  • User Avatar
    0
    jonas452 created

    If every class inherits FullAuditedEntity you can make a new class that inherits FullAuditedEntity and overwrite the Id key field. Otherwise do it manually and map those keys by fluent api.

    For existing classes like Users you must inherit that in a new class and again override the key field.

    Do check that when you choose your PK as a guid that there is not a clustered index on your key. That would cause a performance hit.

    It's generally considered a bad idea to always use a GUID as a primary key.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Hi @Jonas452, thank you for your explanation. You can do it like @Jonas452 said for your new entities but you cannot do it for existing ABP entities.

    Even if you do it, there are some other places like AbpSession contains UserId and TenantId properties. There was a discussion about this issue in ABP github repository. You can also read it if you have time <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/pull/979">https://github.com/aspnetboilerplate/as ... e/pull/979</a>.