It seems to me like the ForeignKeyForeignKey attribute is not working for me, but I guess I'm using it wrong;wrong ;). It's
It's easier to explain with code:
public class BaseCard { public int Id {get ; set; } public int BaseCardId { get; set; } public List<Skill> Skills { get; set; } } public class Skill { public int Id { get; set; } public int BaseCardId { get; set; } [ForeignKey("BaseCardId")] public BaseCard BaseCard { get; set; } } When I try to fill these objects with the seed method, I'm getting this error: INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Skills_dbo.BaseCards_BaseCardId". The conflict occurred in database "Database", table "dbo.BaseCards", column 'Id'.
INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Skills_dbo.BaseCards_BaseCardId". The conflict occurred in database "Database", table "dbo.BaseCards", column 'Id'.
It seems to me like the ForeignKeyForeignKey in SkillSkill tries to point at the IdId column of BaseCardsBaseCards instead of the BaseCardIdBaseCardId column, and I can't figure out why..
If I try to remove the "normal" IdId property of BaseCardBaseCard, and set the BaseCardIdBaseCardId as the PK (with attribute [Key][Key]), I get the following error: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
Does anyone know how I can get this code to work so the property BaseCardIdBaseCardId from the SkillSkill class will point to the BaseCardIdBaseCardId property of BaseCardBaseCard, instead of apparently the IdId property?
Thanks in advance!