对于Oracle的自增量字段,NBear如何处理?

0 views
Skip to first unread message

锦瑟

unread,
Jul 20, 2007, 5:06:57 AM7/20/07
to NBear Google Group
Oracle中的自增量是通过Sequence来实现的,就是插入时用
insert into table (id) values(sequece.nextval)

那么在用Nbear写该实体的insert代码该如何写呢?

Table tb=new Table();
tb.id=??
GateWay.Save<Table>(tb);

Teddy

unread,
Jul 20, 2007, 5:10:54 AM7/20/07
to nbear...@googlegroups.com
NBearV3 对Oracle SEQ的设置方法,可以参照这里:

2007/1/13
Version 3.5.5

Updates:

1) Enhance NBear.Data to support sequence based autoincrement primary key.
   To enable autoincrement primary key for oracle, you must create sequence and trigger for each table like below:

   CREATE SEQUENCE SEQ_TABLENAME;
  
   CREATE OR REPLACE TRIGGER TABLENAME_AUTOINCREMENT
   BEFORE INSERT ON "TABLENAME"
   FOR EACH ROW
   WHEN (NEW.ID IS NULL)
   BEGIN
   SELECT SEQ_TABLENAME.CURRVAL INTO :NEW.ID FROM DUAL;
   END;

只要按这个规则建好SEQ,Insert时没有什么特别,save就可以了。
 
Teddy
 
Reply all
Reply to author
Forward
0 new messages