Hi,
I have a stored proc which takes as input the 'table name' and returns the next id (primary key) for that table. I use this to populate the id's before inserting.
I need to call this stored proc before i insert a row to the table. I am hoping i can do this by using a custom class that implements the IKeyGenerator interface and by using this class in the CustomGenerator attribute for the column property.
ex:
[Devart.Data.Linq.Mapping.KeyGenerator.CustomGenerator(ClassName = "CustomIdGenerator", Parameters = new object[] {"Order"})]
Is there a sample for implementing custom id generators based on which i can do this ? I looked up at the documentation and it has very minimal info on using custom id generators.
Custom Key Generator
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
I'll send you a sample project in a letter, please check that it was not blocked by your mail filter. The sample contains a custom key generator class MyGenerator with the Generate() method calling a stored procedure.
Please note that the ClassName attribute of the CustomGenerator attribute of the key field should contain the assembly-qualified name of the custom generator class. To get this name, please use the 'type' variable defined in the sample.
The tables and the procedure used in the sample are defined as
Please note that the ClassName attribute of the CustomGenerator attribute of the key field should contain the assembly-qualified name of the custom generator class. To get this name, please use the 'type' variable defined in the sample.
The tables and the procedure used in the sample are defined as
Code: Select all
CREATE TABLE DEPT
(
DEPTNO NUMBER(4),
DNAME VARCHAR2(14),
LOC VARCHAR2(13),
CONSTRAINT PK_DEPT PRIMARY KEY (DEPTNO)
);
CREATE TABLE EMP
(
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7, 2),
COMM NUMBER(7, 2),
DEPTNO NUMBER(4),
CONSTRAINT FK_DEPTNO FOREIGN KEY (DEPTNO)
REFERENCES DEPT(DEPTNO),
CONSTRAINT PK_EMP PRIMARY KEY (EMPNO)
);
CREATE OR REPLACE PROCEDURE GetNewId (cnt OUT INTEGER)
AS
BEGIN
SELECT COUNT(*) INTO cnt FROM Dept;
END;