0

For some reason when I set up attributes on a Poco class for tablename and primary key PetaPoco is not seeing them and defaulting to ID autoIncrement = false

[TableName("MyTableName")]
[PrimaryKey("Id", autoIncrement = true)]
public class MyClass
{
    public int Id { get; set; }
    public string Description { get; set; }
}

When I call the Insert() method this fails. If I call the insert method and explicitly pass the table name, primary key column, autoincrement then it works.

Any ideas why Peta Poco is not seeing the attributes?

I am using C# VS 2012 targeting the 4.5 framework

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
Ken Burkhardt
  • 3,528
  • 6
  • 33
  • 45

2 Answers2

0

Try changing your Data DataAnnotations like this:

[DotNetNuke.ComponentModel.DataAnnotations.TableName("MyTableName")]
[DotNetNuke.ComponentModel.DataAnnotations.PrimaryKey("Id", AutoIncrement = true)]
public class MyClass
{
    public int Id { get; set; }
    public string Description { get; set; }
}

Test this out and see if this works for you. I think it's not seeing them in the t4 templates you might have downloaded from NuGet will have the using PetaPoco reference up top and in the DataUtil.cs in the DNN core I believe it's looking for DNN annotations. Not sure if this is a bug, or by design, but I saw this myself and wondered if there were supposed to be t4 templates for just DNN PetaPoco.

I'm not sure about the AutoIncrement being set to false, but notice that I put it in uppercase for the "A".

Hope this helps, I'd keep looking at the next version, I tested this on 7.0.5 and see if they update this or release t4 templates just for DNN PetaPoco.

Sheldon Cohen
  • 441
  • 5
  • 8
0

Try adding PrimaryKeyColumn attribute to the Id property as below

[TableName("MyTableName")]
[PrimaryKey("Id", autoIncrement = true)]
public class MyClass
{
    [PrimaryKeyColumn(AutoIncrement=true)]
    public int Id { get; set; }

    public string Description { get; set; }
}
Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54