Fluent api with postgres ask for a _id column

2 posts, 0 answers
  1. Filippo
    Filippo avatar
    2 posts
    Member since:
    Dec 2010

    Posted 02 Jul 2012 Link to this post

    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


  2. Filippo
    Filippo avatar
    2 posts
    Member since:
    Dec 2010

    Posted 02 Jul 2012 Link to this post

    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
  3. DevCraft banner
Back to Top