I have a table that stores rejected contract proposals.
CREATE TABLE "STATUS_CONTRATO" ( "STC_ID" NUMBER NOT NULL, "CTB_CONTRATO" NUMBER NOT NULL, "STC_DATA" DATE NOT NULL, "STC_OBSERVACAO" VARCHAR2(200) NOT NULL, CONSTRAINT "STATUS_CONTRATO_PK" PRIMARY KEY ( "STC_ID") ENABLE VALIDATE, CONSTRAINT "FK_CONTRATO" FOREIGN KEY ( "CTB_CONTRATO") REFERENCES "CONTRATO" ( CTB_CONTRATO) ON DELETE SET NULL ENABLE VALIDATE) ;
(Script generated by Visual Studio 2010)
There is a simple trigger in this table where STC_ID
:
TRIGGER "STATUS_CONTRATO_TRIGGER1" BEFORE INSERT ON "STATUS_CONTRATO" FOR EACH ROW when (new.STC_ID = 0) DECLARE BEGIN SELECT SEQ_STATUS_ID.NEXTVAL INTO :NEW.STC_ID FROM DUAL; END;
SEQ_STATUS_ID
is a simple sequence.
Here is my problem:
I can successfully complete this insertion in the VS2010 request window:
insert into myschema.STATUS_CONTRATO s( s.STC_ID, s.CTB_CONTRATO, s.STC_DATA, s.STC_OBSERVACAO )values( 0, 10, SYSDATE, 'Inserting by hand works' );
But when I try to insert using EF, I get this exception:
System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Oracle.DataAccess.Client.OracleException: ORA-01400: cannot insert NULL into ("MYSCHEMA"."STATUS_CONTRATO"."STC_ID") ORA-06512: at line 4
I use this code to insert
STATUS_CONTRATO statusContrato = new STATUS_CONTRATO() { STC_ID = 0, CTB_CONTRATO = codContrato, STC_DATA = DateTime.Today, STC_OBSERVACAO = observacao }; ent.STATUS_CONTRATO.AddObject(statusContrato); ent.SaveChanges();
I am using VS2010, Oracle 11g (CentOS Server), ODP.NET client 11.2.0.3.0 Production, .NET Framework 4.0, EF 4.