The following create a primary key for the first column only. Any suggestions please to resolve the issue?
[TableName("tsLcValues")]
[ExplicitColumns]
[PrimaryKey("LcTableID,LcResourceID,CultureISOCode,RowID", autoIncrement = false)]
public class tsLcValue
{
public tsLcValue() { }
[Column("LcTableID")]
[PrimaryKeyColumn(AutoIncrement = false)]
public int LcTableID { get; set; }
[Column("LcResourceID")]
[PrimaryKeyColumn(AutoIncrement = false)]
public int LcResourceID { get; set; }
[Column("CultureISOCode")]
[Length(5)]
[Constraint(Default = "")]
[PrimaryKeyColumn(AutoIncrement = false)]
public string CultureISOCode { get; set; }
[Column("RowID")]
[PrimaryKeyColumn(AutoIncrement = false)]
public int RowID { get; set; }
[Column("ResourceValue")]
[Constraint(Default = "")]
public string ResourceValue { get; set; }
}
I believe the standard version of PetaPoco doesn't support multi column primary keys. There are a couple of custom branches which add this functionality though. I'm not sure how easy it would be to use these with Umbraco though.
The version used by Umbraco is a forked version with some updates to fix some memory perfomrance issues as well, so you won't be able to just swap them out.
Any update on this for umbraco 8? It seems to ignore my primary key attributes and no primary key is created. Otherwise the table is created as expected.
My table definition is
[TableName(DatabaseConstants.QuestionGroupQuestionTable)]
[ExplicitColumns]
[PrimaryKey("questiongroupid,questionid")]
public class QuestionGroupQuestion
{
[Column("questiongroupid")]
public int QuestionGroupId { get; set; }
[Column("questionid")]
public int QuestionId { get; set; }
[Column("sortorder")]
public int SortOrder { get; set; }
[Column("created")]
public DateTime Created { get; set; }
[Column("updated")]
[NullSetting(NullSetting = NullSettings.Null)]
public DateTime? Updated { get; set; }
public override string ToString()
{
return $"QuestionGroupId:{this.QuestionGroupId},QuestionGroupQuestionId:{this.QuestionId},SortOrder:{this.SortOrder},Created:{this.Created},Updated:{this.Updated}";
}
}
Umbraco 8 uses NPoco instead of PetaPoco I believe, and according to the docs, it should be possible to have a composite key, see docs here: https://github.com/schotime/NPoco/wiki/Composite-Primary-Keys (assuming this is the version Umbraco uses).
Fyi i read that link and tried it - the composite key just got ignored - no primary key was created. But see the fix i used with the OnColumns attribute. Thanks.
Combined primary keys with petapoco
The following create a primary key for the first column only. Any suggestions please to resolve the issue?
[TableName("tsLcValues")] [ExplicitColumns] [PrimaryKey("LcTableID,LcResourceID,CultureISOCode,RowID", autoIncrement = false)] public class tsLcValue { public tsLcValue() { }
I believe the standard version of PetaPoco doesn't support multi column primary keys. There are a couple of custom branches which add this functionality though. I'm not sure how easy it would be to use these with Umbraco though.
The version used by Umbraco is a forked version with some updates to fix some memory perfomrance issues as well, so you won't be able to just swap them out.
Maybe you can try to use this
it generate something like this in my mysql db:
fyi, this didnt work for me: it creates the table nicely but, when writing to the database
I get an error:
:(
Any update on this for umbraco 8? It seems to ignore my primary key attributes and no primary key is created. Otherwise the table is created as expected. My table definition is
Umbraco 8 uses NPoco instead of PetaPoco I believe, and according to the docs, it should be possible to have a composite key, see docs here: https://github.com/schotime/NPoco/wiki/Composite-Primary-Keys (assuming this is the version Umbraco uses).
Fyi i read that link and tried it - the composite key just got ignored - no primary key was created. But see the fix i used with the OnColumns attribute. Thanks.
Thanks for the pointer - while you were writing i managed to find the solution by trial and error. The fix was given by the following line:
The full table definition used is:
Thanks John, you're a life saver. This works for Umbraco 9 too :D
is working on a reply...