Oracle. Generating values for Identity Property in Entity Framework

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Sergey_Sch
Posts: 4
Joined: Fri 25 Jul 2014 09:03

Oracle. Generating values for Identity Property in Entity Framework

Post by Sergey_Sch » Sun 16 Aug 2015 19:08

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Mon 17 Aug 2015 14:56

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.

Sergey_Sch
Posts: 4
Joined: Fri 25 Jul 2014 09:03

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

Post by Sergey_Sch » Mon 17 Aug 2015 18:15

Yes, it works. Thank you for help.

Post Reply