Unable to Set a Foreign Key Constraint on ContentTypeDto.
This class is marked as internal, so I cannot leverage it in the same way I create foreign key restraints elsewhere.
I've created similar restraints using UserDto and NodeDto. I suppose my questions are:
Am I creating foreign key restraints correctly?
Was ContentTypeDto intended to be private?
Does a workaround exist?
Migration Fails If My Table Schema Includes a List<T>.
I will gladly come back to this and share some sample code.
Has anyone made the following schema work?
public class Book {
public List<Author> Authors { get; set; }
}
public class Author {
public string Name { get; set; }
}
My attempts to use any List<T> has resulted in a failed migration, preventing the site from booting.
[RESOLVED] Unable to Set a Composite Primary Key with Npoco.
RESOLVED To use a composite primary key, one must annotate a single property with a particular attribute from Umbraco's Database Annotations. I'm confused as to why NPoco's approach does not work. Something like this should be documented, at the very least. If NPoco is not fully adopted/supported, why use it?
Let's say I have a schema defined as such:
[TableName("Example")]
[PrimaryKey("One,Two")]
public class Example {
public int One {get;set;}
public int Two {get;set;}
}
And I create the table as such:
Create.Table<Example>().Do();
When I inspected my new table, the primary key had not been created.
I don't pretend to have the faintest clue what I'm doing regarding NPoco. Could someone kindly tell me if I'm doing something wrong? I'm under the impression that a call to Create.Table<>() should create all the necessary keys based on the attributes I've assigned.
I can manually create Primary Keys via Create.PrimaryKey(), which works. I'd like to understand why my attributes do not work as intended.
With your help I was able to find an example of a composite key in the source code. Leaving this here for anyone else that needs to see a full example (this is of the UserGroup2NodePermission table):
[TableName(Constants.DatabaseSchema.Tables.UserGroup2NodePermission)]
[ExplicitColumns]
internal class UserGroup2NodePermissionDto
{
[Column("userGroupId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_umbracoUserGroup2NodePermission", OnColumns = "userGroupId, nodeId, permission")]
[ForeignKey(typeof(UserGroupDto))]
public int UserGroupId { get; set; }
[Column("nodeId")]
[ForeignKey(typeof(NodeDto))]
[Index(IndexTypes.NonClustered, Name = "IX_umbracoUser2NodePermission_nodeId")]
public int NodeId { get; set; }
[Column("permission")]
public string? Permission { get; set; }
}
Really the thing doing the heavy lifting here is this attribute:
NPoco Questions / Issues I've Ran Into
Unable to Set a Foreign Key Constraint on
ContentTypeDto
.This class is marked as internal, so I cannot leverage it in the same way I create foreign key restraints elsewhere.
I've created similar restraints using
UserDto
andNodeDto
. I suppose my questions are:ContentTypeDto
intended to be private?Migration Fails If My Table Schema Includes a
List<T>
.I will gladly come back to this and share some sample code.
Has anyone made the following schema work?
My attempts to use any
List<T>
has resulted in a failed migration, preventing the site from booting.[RESOLVED] Unable to Set a Composite Primary Key with Npoco.
Let's say I have a schema defined as such:
And I create the table as such:
When I inspected my new table, the primary key had not been created.
I don't pretend to have the faintest clue what I'm doing regarding NPoco. Could someone kindly tell me if I'm doing something wrong? I'm under the impression that a call to
Create.Table<>()
should create all the necessary keys based on the attributes I've assigned.I can manually create Primary Keys via
Create.PrimaryKey()
, which works. I'd like to understand why my attributes do not work as intended.With your help I was able to find an example of a composite key in the source code. Leaving this here for anyone else that needs to see a full example (this is of the UserGroup2NodePermission table):
Really the thing doing the heavy lifting here is this attribute:
is working on a reply...