Custom database table with one-to-many relationship not working.
I'm trying to create two database tables using migrations and NotificationHandlers.
The tables are supposed to have a one-to-many relationship. The DTO:s look like this. I've tried a few different options but I can't get anything to work:
[TableName("Seasons")]
[PrimaryKey("Id", AutoIncrement = true)]
[ExplicitColumns]
public class SeasonsSchema
{
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
[Column("Id")]
public int Id { get; set; }
[Column("SeasonPageId")]
public int SeasonPageId { get; set; }
[Reference(ReferenceType.Many, ColumnName = "TournamentsId", ReferenceMemberName = "TournamentsId")]
public List<TournamentsSchema> Tournaments { get; set; }
}
and
[TableName("Tournaments")]
[PrimaryKey("Id", AutoIncrement = true)]
[ExplicitColumns]
public class TournamentsSchema
{
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
[Column("Id")]
public int Id { get; set; }
[Column("TournamentPageId")]
public int TournamentPageId { get; set; }
}
this is the error thats thrown when starting the application
Ah, no worries. Thanks for reply, I know it was s long while ago and was actually a long shot on my part.
Honestly, I didn't think you'd reply so I dug into the code to find a solution. It turns out, deep in the bowels of the code there's a function that discovers the field names. If the field type is something that can be translated then you get the exception, its thrown by NPoco.
The solution I discovered was to add [Ignore] to the properties or fields that are virtual or lookups. It needed to be the NPoco IgnoreAttribute as there are a few of them.
Custom database table with one-to-many relationship not working.
I'm trying to create two database tables using migrations and NotificationHandlers.
The tables are supposed to have a one-to-many relationship. The DTO:s look like this. I've tried a few different options but I can't get anything to work:
and
this is the error thats thrown when starting the application
If I remove the
from the SeasonsSchema class it obviously work and both tables are created as they should, but there are no relationship between the two tables.
I'm missing something I'm sure but I can't think of anything to try right now.
I tried removing the Reference attribute and I've tried a bunch of things to get this to work but nothing have this far.
Hi Tobias,
Did you ever solve this?
John
Hi, unfortunately not.
We solved it by going another route I think, was very long ago.
Regards Tobias
Ah, no worries. Thanks for reply, I know it was s long while ago and was actually a long shot on my part.
Honestly, I didn't think you'd reply so I dug into the code to find a solution. It turns out, deep in the bowels of the code there's a function that discovers the field names. If the field type is something that can be translated then you get the exception, its thrown by NPoco.
The solution I discovered was to add [Ignore] to the properties or fields that are virtual or lookups. It needed to be the NPoco IgnoreAttribute as there are a few of them.
Ah, probably good to know anyways :)
I'll mark that as an answer while also commenting that I have not tried it myself :)
Thx!
is working on a reply...