Skip to content

Shadow properties ApplicationUserId and ApplicationRoleId created in UserRoles table when using ef migrations with IdentityModel #35842

@laorient

Description

@laorient

Bug description

I tried it in both net8.0 (8.0.14) and net9.0 (9.0.3) latest versions and both creates the shadow columns like below:

CREATE TABLE [UserRoles] (
    [UserId] nvarchar(450) NOT NULL,
    [RoleId] nvarchar(450) NOT NULL,
    [Type] nvarchar(50) NOT NULL,
    [TenantId] uniqueidentifier NULL,
    [CreatedAt] datetime2 NULL,
    [ModifiedAt] datetime2 NULL,
    [CreatedBy] nvarchar(max) NULL,
    [ModifiedBy] nvarchar(max) NULL,
    [IsActive] bit NULL,
    [ApplicationRoleId] nvarchar(450) NULL,
    [ApplicationUserId] nvarchar(450) NULL,
    CONSTRAINT [PK_UserRoles] PRIMARY KEY ([UserId], [RoleId]),
    CONSTRAINT [FK_UserRoles_Roles_ApplicationRoleId] FOREIGN KEY ([ApplicationRoleId]) REFERENCES [Roles] ([Id]) ON DELETE CASCADE,
    CONSTRAINT [FK_UserRoles_Roles_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [Roles] ([Id]) ON DELETE CASCADE,
    CONSTRAINT [FK_UserRoles_Users_ApplicationUserId] FOREIGN KEY ([ApplicationUserId]) REFERENCES [Users] ([Id]) ON DELETE CASCADE,
    CONSTRAINT [FK_UserRoles_Users_UserId] FOREIGN KEY ([UserId]) REFERENCES [Users] ([Id]) ON DELETE CASCADE
);

Basically I created custom ApplicationUser, ApplicationRole, then ApplicationUserRole to customize them. But I can never get rid of the two shadow columns, despite all efforts. It looks like a bug when EF Core is dealing with Many-to-many and join table with payload. I tried the approach on https://learn.microsoft.com/en-us/ef/core/modeling/relationships/many-to-many.
See my project attached.

EFEntityTest.zip

Your code

See attached file.

Stack traces


Verbose output


EF Core version

9.0.3

Database provider

No response

Target framework

No response

Operating system

No response

IDE

No response

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions