PostGreSQL - Entity insert - Dduplicate key value violates unique constraint

173 views Asked by At

I'm having this erro when trying to insert a new record on database:

"Duplicate key value violates unique constraint"

This is my insert method:

            using ( DataContext objDB = new DataContext() )
            {
                objDB.Set<T>().Add( item );
                objDB.Entry( item ).State = EntityState.Added;
                objDB.SaveChanges();
                return item;
            }

The table that I'm trying to insert is like this in EDMX modeling:

<EntityType Name="tb_functionality">
  <Key>
    <PropertyRef Name="id" />
  </Key>
  <Property Name="id" Type="int4" StoreGeneratedPattern="Identity" Nullable="false" />
  <Property Name="name" Type="varchar" MaxLength="100" Nullable="false" />
</EntityType>

And the object that I'm trying to insert ('item') is like this on code:

ID=0 Name='Test'

What is wrong on my code? This works perfect when I'm using SQL Server, so in PostGre I have to chance anything on my model or insert method?

Thanks in advance for the help.

0

There are 0 answers