Scaffolding Database with default AspNetCore Identity tables.
Hi Team,
I have a database that has the default AspNetCore user tables (AspNetUsers, AspNetUserRoles etc. ) in them.
My goal was to be able to scaffold the Database, and make it descend from the default IdentiyDbContext<TUser>
I accomplished this with overriding SqlServerDatabaseModelFactory and filter out all the tables that start with AspNet
I also override CSharpDbContextGenerator class and do a brute string replace (Replacing DbContext with IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>) to get it descend from the DbContext I want.
So MyDbContext.cs looks like:
public partial class MyDbContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>
{
...
}
This all works well, for 1 exception. Every Relation to any of the AspNet tables will result in the following error
Could not scaffold the foreign key 'dbo.BankAccounts(CreatedBy)'. The referenced table 'dbo.AspNetUsers' could not be scaffolded.
This is understandable, as I have filtered out the tables in the DataBaseModel Is there another way to get the same result, but with the correct Metadata generated for these relations?
Include provider and version information
EF Core version: 6.0.8 Database provider: Microsoft.EntityFrameworkCore.SqlServer
@MariovanZeist You should be able filter tables using the command line options, or @ErikEJ's Power Tools. For the rest, I suspect a modified template (#4038) will be an easier route to this goal.