Oracle 11g ODAC Entity Framework - how to auto increment a number
905813Dec 16 2011 — edited Dec 11 2012Hello,
I recently downloaded 11.2.0.2.30 of ODAC (the version covered in this tutorial http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/EntityFrameworkOBE/EntityFrameworkOBE.htm) so that I can write a .NET MVC app against an Oracle database.
I've never done any work with Oracle DB's before and found out today that the auto increment of a key field doesn't just 'happen' like it does in a SQL Server table (yeah, I know how dumb this sounds).
There's a History table in my Oracle DB. It has a sequence on it called 's_history'. But I don't know how to make the table automatically add an incremented number via the Entity Framework. Here's some code:
Using context As New DBEntities
Dim h As New HISTORY
h.YEAR = 2011
h.MONTH = 12
context.HISTORies.Add(h)
context.SaveChanges()
End Using
If I run this then no row gets created because the HISTORY_ID column can't be NULL. I can set the HISTORY_ID colum to a valid number and the row will get created. But how do I get the Entity Framework to optimistically lock the row and generate the next available ID for me?