New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions about "IsNew" and "Save" #10
Comments
You're right... PetaPoco assumes primary keys are populated by the DB... I've been meaning to address this but just haven't yet. |
Thanks for the quick response. These kinds of issues are easy enough to work around when you are aware of them. I think it might be worthwhile to document these kinds of assumptions so people don't get caught by surprise. I think you have done a great job with PetoPoco and look forward to following its progress. |
I've just committed fixes to support for non-auto-increment/non-identity primary key columns. Insert() should now work correctly, but IsNew() and Save() will not.... there's simply no way for PetaPoco to know. In GitHub only atm... will include in next NuGet package. |
Thanks for the quick response...very impressive. Keep up the good work! On Fri, Apr 22, 2011 at 7:34 AM, toptensoftware <
|
Yep I hit this one too and had to write an alternate Save() that checks an Exists() on the PK value before deciding to do the update or insert. Mind you my PK is a VARCHAR and not an AUTO INCREMENT so methinks that you must be caching the largest autoincrement which is why IsNew() does sweet FA i.e. doesn't query the database that I can see BUT now I do entirely understand why! ;-) And yes Insert and Update work as long as I don't insert a false for AutoIncrement in the parameter list for the former. Upsert() anyone that does what I am doing above with Exists on a specified PK? |
Am I correct to assume that "IsNew" and "Save" will only work properly if the database is using an auto generating primary key?
If the the database is using a "natural" primary key like an invoice number that is being created by the program then that property will be populated by the program when the object is created and the IsNew function will return false (because the primary key is populated) even though the record is not already in the database. Therefore, "Save" will not work properly.
Am I understandingt that correctly? If so, are there any plans to have these functions work with "natural" primary keys?
The text was updated successfully, but these errors were encountered: