EFDesigner icon indicating copy to clipboard operation
EFDesigner copied to clipboard

ASP.NET Core Identity support [Feature Request]

Open mmarinchenko opened this issue 6 years ago • 12 comments

To support custom ASP.NET Core Identity scenario with EFDesigner some manual work has to be done.

  1. Implement 7 custom entities which inherit types from Microsoft.AspNetCore.Identity namespace:
  • IdentityUser
  • IdentityRole
  • IdentityUserClaim<TKey>
  • IdentityUserRole<TKey>
  • IdentityRoleClaim<TKey>
  • IdentityUserLogin<TKey>
  • IdentityUserToken<TKey>

Note: TKey type parameter defaults to string type.

  1. Implement custom part of EFDesigner-generated DbContext class to define 7 respective DbSets and create model using partial OnModelCreatedImpl() method.

  2. Somehow inherit IdentityDbContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken> type from Microsoft.AspNetCore.Identity.EntityFrameworkCore namespace instead of default DbContext from Microsoft.EntityFrameworkCore.

Note: IdentityDbContext<> in turn inherits DbContext.

First 2 points are manual work because EFDesigner lacks:

  • support for generated entity to inherit any type (not just other entity type defined on a diagram);
  • support for string type to be used as identity (actually not a strong requirement because Int64 may be used for TKey type parameter).

This is safe to implement. Not a big problem actually.

But 3rd point needs to copy EFCoreDesigner.ttinclude template to a project directory and remove the : Microsoft.EntityFrameworkCore.DbContext text from it. Then in file from point 2 add something like : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext<MyUser, MyRole, string/*TKey*/, MyUserClaim, MyUserRole, MyUserLogin, MyRoleClaim, MyUserToken>.

This introduces a problem to EFDesigner extension updates management. So it would be great to implement string property in EFDesigner for setting custom base class for DbContext (like ConnectionString). Truth to be told it's the only crusial part of all this request :)

mmarinchenko avatar Feb 01 '19 14:02 mmarinchenko