© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
1 reply
ægteemil

❔ The foreign key property 'UserRole.RoleId1' was created in shadow state

I've expanded the default
IdentityUserRole
IdentityUserRole
implementation for .NET identity like this:
public class UserRole : IdentityUserRole<Guid>
{
    public Guid TenantId { get; set; }
    public virtual Tenant Tenant { get; set; } = null!;
    
    public virtual User User { get; set; } = null!;
    public virtual Role Role { get; set; } = null!;
}
public class UserRole : IdentityUserRole<Guid>
{
    public Guid TenantId { get; set; }
    public virtual Tenant Tenant { get; set; } = null!;
    
    public virtual User User { get; set; } = null!;
    public virtual Role Role { get; set; } = null!;
}

And I've included the
User
User
and
Role
Role
as navigation properties, which is now causing EF to write this when creating a migration:
The foreign key property 'UserRole.RoleId1' was created in shadow state because a conflicting property with the simple name 'RoleId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type
The foreign key property 'UserRole.RoleId1' was created in shadow state because a conflicting property with the simple name 'RoleId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type

I'm not sure how to configure this properly and avoid the new foreign key property
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Ef core creating shadow foreign key, why?
C#CC# / help
3y ago
SqlException: The INSERT statement conflicted with the FOREIGN KEY
C#CC# / help
2y ago
Shadow property, but property is defined?
C#CC# / help
3y ago
Entity Framework Foreign Key
C#CC# / help
2y ago