Base solution for your next web application
Open Closed

Bi-directional database sync without GUID PK - Is this possible? #6107


User avatar
0
magstim created

Hello,

I've recently downloaded the demo APP for AspNetZero, with the hope of using it as the basic for an upcoming project. However the application we are looking to develop requires multiple devices to sync (bi-directionally) with a central server, all changes are then pushed out to each client. Each client device will maintain its own local database in order to support offline usage, and will sync with the server when needed.

My problem is that I don't believe this would be possible to do with Abp (and thus AspZero) since the PK type for all out-of-the-box entities are either int or long. Consider a scenario whereby we have 5 clients all synced with the central database. Each client then creates a different "User" entity it its local store, and because PK is auto increment int they would all be assined the same value. When it comes time to sync we would have 5 Users all with the same PK value. This is obviously a big problem, particulaly in cases where there are other tables in the database which store data related to a user using PK as a foreign key. I believe a solution would be to change the default PK type for all entities to use a unique identifier (such as GUID).

I know changing the PK type to GUID (with Abp framework) has been discussed at length in various posts on GitHub, particularly #979 and from what I read this is not something that is going to happen in the Apb framework - and I can understand the reasons for that.

My question is really this:

For my use case (i.e. bi-directional sync requrie) could AspZero work? Are there techniques for database synchronisation when PK is an int? I couldn't seem to find any with a quick google search - and most scenarios recommend using PK of GUID whenever database synching is a requirement.

Any thoughts would be welcome.


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

    Hi @magstim

    You are right, there is no easy way for data sync when using non-guid PKs. You can add an ExtUserId (Guid) field to your user-related entities and ExtId (Guid) to your UserEntity and use those fields during data sync operation.

    Currently I don't think of a better solution.

  • User Avatar
    0
    magstim created

    Thanks for your reply.

    I was thinking along the same lines as your suggestion. My thought was to add an 'EntityId' (Guid) field to all entities (User, Tenant, Role) + any domain entities and use those for syncing, basically ignore the int PK. I just need to try and convice myself that this would work!