How does DBEntry know if it should update or insert when Calling Save methode

Jul 27, 2008 at 4:41 PM
I have an issue when I try to import data. The import now works fine, but when I try to reimport the data, I got an FbException "can't store duplicate value in index". This is correct, because I use a AutoIncrement ID and there is a column with a number which should be unique. So how can I tell DBEntry to update the entry instead of trying to insert values again? When I don't use an ID and only the number als DBkey everything works fine, but this is bad design. The PK should not contain any information.

Any ideas?
Coordinator
Jul 28, 2008 at 7:09 AM
DbEntry use the default value of PK to judge if it is insert or update. If the type of PK is int or long, the default value is 0. If the type of PK is Guid, the default value of it is Guid.Empty.

If you want it to be update, you could set Id as value which already exists in database.
And you may call update function manually: DbEntry.Context.Update (it also need you to set Id first).

And if your models are not inherits from DbObjectMode<>, the DbKey attribute on PK field may have DefaultValue argument to tell DbEntry how to judge if it is insert or update.

Hope it help.

Thanks.