Question

I have a table and a sequence in 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 ;

I also have a class defined in 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; }
    }
}

I further have a DTO class and a service class and data repository class where I have a data insert code:

...
using (var db = DbConnectionFactory.OpenDbConnection())
{
  db.Insert(data);
}
...

When I try to insert the record I get "ORA-02289: sequence does not exist".

How do I tell OrmLite which sequence to use?

Was it helpful?

Solution

The reason, why you are getting ORA-02289 is because there is no information where to look for a sequence.

All you need to do is to add the [Sequence()] attribute at the top of a class where your data model class is defined. If you would have a data table TABLE1 and a corresponding sequence SEQ_TABLE1 defined in Oracle database, then your example would be:

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; }
    }
}

This should now add new records into Oracle table, using the sequence as defined.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top