Base solution for your next web application
Open Closed

Auto-Increment / New GUIDs in DB Migration #1384


User avatar
0
andry3ag created

When creating new entities, is there any way to specify that an Id should be auto-incremented, or in the case of uniqueidentifier/GUID, invoke NEWID() as a default value?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can define a base entity class which inherits from Entity<Guid> and set it's id property on constructor to new Guid();

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    andry3ag created

    What about integer autoincrement?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You dont have to do anyting for integers. It's auto increment by default. Do you have any problem about it ?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    As Halil pointed out, there is also no need to set Guid identity fields. Because it's generated by abp with sequential guid generator.

    It has better performance than regular guid generation.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)