Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this is my postgres table
SQL
CREATE SEQUENCE student_id_seq;
CREATE TABLE student
(
  id integer NOT NULL  default nextval('student_id_seq'),
  first_name character varying,
  CONSTRAINT student_pkey PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);

ALTER TABLE student
  OWNER TO postgres;
ALTER SEQUENCE student_id_seq owned by student.id;


I have write class for nhibernate like below...
C#
[Class(Table = "student")]
public class Student
{
 private long _id;
 private string _studentname;
[Id(Name = "Id", Column = "id", UnsavedValue="0" )]
        [Generator(1, Class = "sequence")]
        [Param(Name = "student_id_seq")]
        public virtual long Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [Property]
        [Column(1, Name = "studentname")]
        public virtual string studentname
        {
            get { return _studentname; }
            set { _studentname=value; }
        }
//other methods...
}


It throws error while call...
C#
session.SaveOrUpdate(obj);

Error: could not get next sequence value

thanks
Posted
Updated 11-Apr-13 21:11pm
v2
Comments
Bernhard Hiller 11-Apr-13 2:58am    
Doesn't postgres have a datatype for the autoincrementing integer - I thought it was "serial".
Aarti Meswania 11-Apr-13 3:06am    
I have change sequence to serial
[Generator(1, Class = "serial")]
but still not working

1 solution

I have solve this
hope it will useful to them who facing same problem...
C#
[Class(Table = "student")]
public class Student
{
 private long _id;
 private string _studentname;
[Id(Name = "Id", Column = "id", UnsavedValue="0" )]
        [Generator(1, Class = "sequence")]
        [Param(2,Name = "sequence", Content = "student_id_seq")] // Line I have changed
        public virtual long Id
        {
            get { return _id; }
            set { _id = value; }
        }
 
        [Property]
        [Column(1, Name = "studentname")]
        public virtual string studentname
        {
            get { return _studentname; }
            set { _studentname=value; }
        }
//other methods...
}

NOTE : postgres is case sensitive if you have write name of object in double quote then you have to write name in .net in exact manner. so, when create sequence do not write sequence name (e.g. student_id_seq) in double quotes

Happy Coding!
:)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900