I have a serial field (called displayID) that is not the key of the table in a postgresql database and I am working with entity framework code first. When I add new objects into the database through the context, I save the object but it inserts into the database with a value of 0 rather than the next integer. I can't get it to auto-increment the value in the database. I'm using devArt postgres entity framework driver. Is there something special I have to do?
Try adding the Identity Data Annotation to your displayID property. Don't know if the DevArt stuff supports that but it should work.
public class Foo
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int displayID { get; set; }
[Key]
public int myKey { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With