Shadow properties ApplicationUserId and ApplicationRoleId created in UserRoles table when using ef migrations with IdentityModel
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
### 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](https://github.com/user-attachments/files/19441503/EFEntityTest.zip)
### Your code
```csharp
See attached file.
```
### Stack traces
```text
```
### Verbose output
```text
```
### EF Core version
9.0.3
### Database provider
_No response_
### Target framework
_No response_
### Operating system
_No response_
### IDE
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.