Question in relation to this, here...
UserManager.AddToRole not working - Foreign Key error
In my application I have a custom Role implementation
public class Role : IdentityRole<Guid, UserRole>
{
public const string Admininstrator = "Administrator";
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public new Guid Id { get; set; }
}
but when used causes this error
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUserRoles_dbo.AspNetRoles_RoleId". The conflict occurred in database "TestDatabase", table "dbo.AspNetRoles", column 'Id'.
The culprit is this...
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public new Guid Id { get; set; }
removing this from the class and manually creating a unique ID works...
public Role()
{
Id = Guid.NewGuid();
}
I would prefer the database did this for me - any ideas why this is failing?