This is a migrated thread and some comments may be shown as answers.

Fluent api with postgres ask for a _id column

1 Answer 46 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Filippo
Top achievements
Rank 1
Filippo asked on 02 Jul 2012, 12:03 PM
Hi everybody,
This is my first post on this forums.
I am using Openaccess Orm Fluent API for six months using mvc and i hadn't had any problem on two projects. Now get an error on an Asp.net project.

Following the documentation i usually set up an object like this:

public class SampleItem
   {
       public int gid { get; set; }
       public string Userins { get; set; }
       public string Usermod { get; set; }
       public DateTime Dateins { get; set; }
       public DateTime Datemod { get; set; }
   }

and i configure the Metadata source like this

MappingConfiguration<SampleItem> sampleItemConfiguration = new MappingConfiguration<SampleItem>();
            sampleItemConfiguration.MapType(x => new
            {
                gid = x.gid,
                userins = x.Userins,
                usermod = x.Usermod,
                dateins = x.Dateins,
                datemod = x.Datemod
            }).ToTable("pcarchi");
            sampleItemConfiguration.HasProperty(x => x.gid).IsIdentity(KeyGenerator.Autoinc);
            sampleItemConfiguration.HasProperty(x => x.gid).IsNotNullable();
            sampleItemConfiguration.HasProperty(x => x.Dateins).IsNotNullable();
            sampleItemConfiguration.HasProperty(x => x.Datemod).IsNotNullable();
            sampleItemConfiguration.HasProperty(x => x.Userins).IsNotNullable();
            sampleItemConfiguration.HasProperty(x => x.Usermod).IsNotNullable();


The Table pcarchi is defined like this

CREATE TABLE pcarchi
(
  gid serial NOT NULL,
  userins character varying(50) NOT NULL,
  usermod character varying(50) NOT NULL,
  dateins timestamp without time zone NOT NULL,
  datemod timestamp without time zone NOT NULL
  CONSTRAINT ccarchi_pkey PRIMARY KEY (gid)
)
WITH (
  OIDS=FALSE
);

When i try to get a SampleItem i always get this error: 


SELECT a."pcarchi_id" AS COL1, a."dateins" AS COL2, a."datemod" AS COL3, a."userins" AS COL4, a."usermod" AS COL5, a."gid" AS COL6 FROM "pcarchi" AS a ORDER BY COL2 DESC, COL1  Telerik.OpenAccess.RT.sql.SQLException: ERROR: 42703: column a.pcarchi_id does not exist

It always add a ..._id column to select statement. Is there a particular configuration that i have to set in order to make it work?

Thanks in advance

Filippo


1 Answer, 1 is accepted

Sort by
0
Filippo
Top achievements
Rank 1
answered on 02 Jul 2012, 09:50 PM
I found the error. You must not set IsNotNullable the primary key.


sampleItemConfiguration.HasProperty(x => x.gid).IsIdentity(KeyGenerator.Autoinc);
//sampleItemConfiguration.HasProperty(x => x.gid).IsNotNullable();

Bye
Tags
General Discussions
Asked by
Filippo
Top achievements
Rank 1
Answers by
Filippo
Top achievements
Rank 1
Share this question
or