Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Adding a new record via Entity Framework 6

3687299Apr 13 2018 — edited Apr 18 2018

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?

This post has been answered by Alex Keh-Oracle on Apr 13 2018
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 11 2018
Added on Apr 13 2018
1 comment
1,157 views