Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Servicestack Ormlite中使用Oracle序列_Oracle_<img Src="//i.stack.imgur.com/WM7S8.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">ormlite Servicestack - Fatal编程技术网 ormlite-servicestack,Oracle,ormlite Servicestack" /> ormlite-servicestack,Oracle,ormlite Servicestack" />

如何在Servicestack Ormlite中使用Oracle序列

如何在Servicestack Ormlite中使用Oracle序列,oracle,ormlite-servicestack,Oracle,ormlite Servicestack,我在Oracle中有一个表和一个序列: CREATE TABLE USER1.TABLE1 ( ID number(9,0) NOT NULL, FIELD_1 nvarchar2(64) NOT NULL, FIELD_2 nvarchar2(256), CONSTRAINT PK_TABLE1 PRIMARY KEY ( ID ) ) ; CREATE SEQUEN

我在Oracle中有一个表和一个序列:

CREATE TABLE USER1.TABLE1 ( 
    ID                   number(9,0)  NOT NULL,
    FIELD_1              nvarchar2(64)  NOT NULL,
    FIELD_2              nvarchar2(256),
    CONSTRAINT PK_TABLE1 PRIMARY KEY ( ID )
) ;

CREATE SEQUENCE USER1.SEQ_TABLE1 START WITH 1 ;
我还有一个用C定义的类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServiceStack.DataAnnotations;

namespace OraTest
{
    public class Table1
    {
        [AutoIncrement]
        public int      Id { get; set; }
        public string   Field_1 { get; set; }
        public string   Field_2 { get; set; }
    }
}
我还有一个DTO类、一个服务类和数据存储库类,其中我有一个数据插入代码:

...
using (var db = DbConnectionFactory.OpenDbConnection())
{
  db.Insert(data);
}
...
当我尝试插入记录时,我得到ORA-02289:序列不存在


我如何告诉OrmLite使用哪个序列?

之所以得到ORA-02289,是因为没有信息可以在哪里查找序列

您只需在定义数据模型类的类的顶部添加[Sequence]属性。如果在Oracle数据库中定义了数据表TABLE1和相应的序列SEQ_TABLE1,则示例如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServiceStack.DataAnnotations;

namespace OraTest
{
    public class Table1
    {
        [AutoIncrement]
        [Sequence("SEQ_TABLE1")]
        public int      Id { get; set; }
        public string   Field_1 { get; set; }
        public string   Field_2 { get; set; }
    }
}
现在应该使用定义的顺序将新记录添加到Oracle表中