Oracle. Generating values for Identity Property in Entity Framework
Posted: 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.
DDL:
file.edml (SSDL content) (I check it following instructions in http://blog.devart.com/set-identity-and ... ggers.html):
C# code:
At runtime, I getting the next error:
My dbMonitor SQL result view:
Where :p0 == "qq" and :p1 == "ee" but ID column is missing.
Code: Select all
Oracle 11.2.0.1 Database
Code: Select all
VS 2015 + Devart Entity Developer Tool 5.8.662
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)
)
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>
Code: Select all
public Task CreateAsync()
{
var ap=new AuditPermission
{
RoleId = "qq",
UserId = "ee"
};
_context.AuditPermissions.Add(ap);
return _context.SaveChangesAsync();
}
Code: Select all
ORA-01400: cannot insert NULL into ("AUDIT_PERMISSIONS"."ID")
ORA-06512: at line 4
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;