PetaPoco icon indicating copy to clipboard operation
PetaPoco copied to clipboard

Incorrect AutoIncrement for GUID typed PK

Open ghost opened this issue 8 years ago • 2 comments

I have a table which has a PK of type GUID and its IsIdentity has been set to false but PetaPoco consider it as true! and I'm getting this exception:

The target table of 'TABLE_NAME' the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.

I'm using PetaPoco 5.1.228

ghost avatar Feb 20 '17 19:02 ghost

@hfakouri Could you provide sample code to reproduce this. I'll add it as an integration test

pleb avatar Feb 28 '17 01:02 pleb

Create a table in SQL Server and name it Customers. Add a column and name it CustomerCode ([uniqueidentifier] NOT NULL) and set its IsIdentity = false.

Now use T4 templates for generating Database.cs

Generated code would be like this: [TableName("dbo.Customers")] [PrimaryKey("CustomerCode")] [ExplicitColumns] public partial class Customers : XXXDB.Record<Customers> { [Column] public Guid CustomerCode { get; set; } ... }

and then try to do Save() or db.Insert(). You get the exception.

My hack was I manually edited the generated Database.cs and set the auto increment to false for primary key column:

[TableName("dbo.Customers")] [PrimaryKey("CustomerCode", AutoIncrement = false)] [ExplicitColumns] public partial class Customers : XXXDB.Record<Customers> { [Column] public Guid CustomerCode { get; set; } ... }

sfakouri avatar Mar 03 '17 19:03 sfakouri