With Visual Studio 2017 installed the developer tools, setup a test project that simply sets up a dbContext, adds a new entry, does a save which should return the new primary key but instead returns the following error
Oracle version 11.2.0.3.0
Error message
ORA-01400: cannot insert NULL into ("OCS"."SEQUENCETEST_TABLE"."ID")
ORA-06512: at line 4
Table definition
CREATE TABLE "OCS"."SEQUENCETEST_TABLE"
( "ID" NUMBER(*,0),
"OTHERCOLUMN" VARCHAR2(255 BYTE),
PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "TS_OCS" ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "TS_OCS" ;
Sequence
CREATE SEQUENCE SEQUENCETEST_SEQUENCE START WITH 1 INCREMENT BY 1
Code which fails with the error message above.
using (Entities1 context = new Entities1())
{
var item = new SEQUENCETEST_TABLE() { OTHERCOLUMN = "From VS2017" };
context.SEQUENCETEST_TABLE.Add(item);
context.Entry(item).State = System.Data.Entity.EntityState.Added;
try
{
context.SaveChanges();
Console.WriteLine(item.ID);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Additionally StoreGeneratedPattern is set to identity which it was not originally.
So my question. have I done something incorrectly?