Page 1 of 1

Oracle. Generating values for Identity Property in Entity Framework

Posted: Sun 16 Aug 2015 19:08
by Sergey_Sch
Hello. I need help in using EF6 and Oracle Sequence object for insert/update a records with identity column.

Code: Select all

Oracle 11.2.0.1 Database

Code: Select all

VS 2015 + Devart Entity Developer Tool 5.8.662
DDL:

Code: Select all

CREATE TABLE AUDIT_PERMISSIONS (
  ID      NUMBER(12, 0)     NOT NULL,
  USER_ID VARCHAR2(30 CHAR) NOT NULL,
  ROLE_ID VARCHAR2(30 CHAR) NOT NULL,
  CONSTRAINT AUDIT_PERMISSIONS_PK PRIMARY KEY (ID) USING INDEX TABLESPACE MP_IDX STORAGE (INITIAL 64 K
                                                                                          NEXT 1 M
                                                                                          MAXEXTENTS UNLIMITED)
)
file.edml (SSDL content) (I check it following instructions in http://blog.devart.com/set-identity-and ... ggers.html):

Code: Select all

<EntityType Name="AUDIT_PERMISSIONS">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="int" Nullable="false" devart:DefaultValue="SEQ_AUDIT_PERMISSIONS.NEXTVAL" StoreGeneratedPattern="Identity">
          </Property>
          <Property Name="USER_ID" Type="VARCHAR2" Nullable="false" MaxLength="30">
          </Property>
          <Property Name="ROLE_ID" Type="VARCHAR2" Nullable="false" MaxLength="30">
          </Property>
        </EntityType>
C# code:

Code: Select all

public Task CreateAsync()
{
    var ap=new AuditPermission
    {
        RoleId = "qq",
        UserId = "ee"
    };

    _context.AuditPermissions.Add(ap);
    return _context.SaveChangesAsync();
}
At runtime, I getting the next error:

Code: Select all

ORA-01400: cannot insert NULL into ("AUDIT_PERMISSIONS"."ID")
ORA-06512: at line 4
My dbMonitor SQL result view:

Code: Select all

DECLARE
  updatedRowid ROWID;
BEGIN
INSERT INTO AUDIT_PERMISSIONS(USER_ID, ROLE_ID)
VALUES (:p0, :p1)
RETURNING ROWID INTO updatedRowid;
OPEN :outParameter FOR SELECT ID FROM AUDIT_PERMISSIONS WHERE ROWID = updatedRowid;
END;
Where :p0 == "qq" and :p1 == "ee" but ID column is missing.

Re: Oracle. Generating values for Identity Property in Entity Framework

Posted: Mon 17 Aug 2015 14:56
by Shalex
Have you set the following option in your code?

Code: Select all

  // Here we configure the EF-provider, so that the default values defined in the model are used 
  var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
  config.DmlOptions.InsertNullBehaviour = InsertNullBehaviour.InsertDefaultOrNull;
If this doesn't help, send us a small test project for reproducing the issue in our environment.

Re: Oracle. Generating values for Identity Property in Entity Framework

Posted: Mon 17 Aug 2015 18:15
by Sergey_Sch
Yes, it works. Thank you for help.