ORMLite AutoId Issue on Insert when we have an existing Guid

I try to sync data between my mobile app and the SQL server DB.

In my mobile app I use:

[PrimaryKey, AutoId]
public Guid RowId { get; set; }

When I create data on the device no issue all good, I push to the server my info, I have the same guid.

If I uninstall my app I have to resend the data to the mobile device.
So the Guid exist in my serverRecord that I want to insert.

When I call Db.Insert(serverRecord). The Guid I received from the server is overwrite.

So on the local device I have my record with a new RowId, when I push again my data to the server I have a new record cause my RowId was changed.

Is it possible when we call Db.Insert to keep the Guid if there is one and only if it’s null or Guid.Empty to generate a new one ?

I’ve changed it to use the existing Id value if provided in this commit.

This change is available from v5.1.1 that’s now available on MyGet.

Oh Great :smile:

Does Db.Save() call Db.Insert() behind the scene ?

Yes Save() uses Inserts for inserting new records.