-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASP.NET Core Identity support [Feature Request] #38
Comments
Intriguing. I'll look into it. Thanks for the suggestion. As an aside, your comment above:
isn't completely accurate. Since generated entities are partial classes, you can declare a base class in a custom partial file as long, of course, as there isn't any other base class for that type in your model. |
Thanks, @msawczyn! You're right, I was not completely accurate about entity inheritance. I guess I wrote too many words :) In fact I created this feature request mainly becuase of point 3. As for the entity inheritance... This is difficult. Since the base type (e.g. |
I really think this is going to need totally separate tt template generators. Several critical factors:
The last item I think is the game changer. I'm not sure how to even approach this.
Hmm. Am speaking aloud here. Welcome any thoughts. I truly wish I had more time to work on this aspect. Pulling hair out as it is. +1 vote on feature request from me. |
Thanks for the excellent input! Let's hit those up in order:
As always, I welcome any contributions you might have time for. I'm a bit swamped at work right now and don't have a lot of time to work in many (any?) hours for the designer, but that should change in a couple of handfuls of weeks. This is an intriguing problem! Thanks again for the input. |
…asses (drag/drop). See issue #53
I was going to create a sample project, but ran out of time. If I can find time this week, I'll submit a git repo in this issue for a working proof of concept AspNetCore project.
Additional /etc Not related to Identity but valuable...
|
I performed some additional tests for ASP.NET Core scenario and realize that first 2 points of original request are not needed for default identity support :) The only thing that needs to be done is point 3. P.S. I also mention this in issue msawczyn/EFDesigner#72. |
Just wanted to let you know that I've started implementing this, both in EF6 and EFCore. If you'd like to follow the progress (and contribute!) the branch is called |
I've rewritten the Asp Core Identity for Mvc. Feel free to take a look at https://github.com/prince272/AspCoreIdentityMvc Simply change the url for the area 'Identity' to 'IdentityMvc' and you'll be automatically directed to the Mvc version for Identity. |
Nice ... thanks! I'll dig into that. I've got the changes needed in the designer pretty much done, so the next step is the code generation. This will certainly help. |
Hi @msawczyn , I'm also interested in this topic. Is there way to speed up things by helping you out in this issue/enhancement ? |
Absolutely! Always happy to have the help! The goal, obviously, is to create a mechanism where the user can easily scaffold a model that will work with asp.net identity, then be able to modify it to their needs without breaking its compatability. There's an older branch named Thanks for volunteering. |
Hey all, just wanted to let you know that, even after being on the list for a year, this isn't being ignored ... it just keeps getting bumped down in priority. It's not a simple task to get this right so that it can be used as a general modeling aid (will definitely require a custom starting project item) and will need some basic infrastructure before it can be implemented. The EFCore5 release is taking up all available hours to get solid. But I haven't forgotten! |
Greetings, I've been using your extension myself and with fellow developers. I hope changing the code base for 2022 made some room to give priority for this request. Using this great tool with built-in identity solution would makes us more than happy. Thanks again. |
I have been using Entity Framework Visual Editor for a few years now; it has been a great tool for quickly reasoning about my data models. However, I am accumulating tech debt in a few different projects now from lack of integration of this tool with Microsoft Identity. I first attempted to resolve this on my own here. I have since started up a few projects where I maintain 2 separate "user"/"person" tables with a 1-1 relationship. This has resulted in lots of extra files, classes, lines of code, SQL queries, and general obscurity that probably leads down paths away from best practices. Here is an example of a "best" solution I could come up with after way more time than I would like to have spent:
And then on the Razor index page:
Does anyone have any better workarounds, or solutions for this disconnection of EF Visual Editor from Microsoft's Identity model? |
And, the code I just posted above has broken another line of code where I was doing:
in another Razor page. I will have to write even more logic to gracefully handle when I have the User ClaimsPrincipal, but not the IdentityUser - in all of my projects. I google search get IdentityUser from ClaimsPrincipal, and there are no results - this is a big red flag for me, and I am very concerned about the viability of my projects being designed with this tool now. |
@Mattnificent, the data context class generated from the EF model is partial. It has partial methods for customization purposes: partial void CustomInit(DbContextOptionsBuilder optionsBuilder);
partial void OnModelCreatingImpl(ModelBuilder modelBuilder);
partial void OnModelCreatedImpl(ModelBuilder modelBuilder); Therefore, in this particular case, you can manually add the <YourEFModelName>.custom.cs file with the following text: public partial class <YourEFModelName>
{
partial void OnModelCreatedImpl(ModelBuilder modelBuilder) =>
modelBuilder.Entity<Person>()
.HasOne<IdentityUser>(p => p.AspNetUser)
.WithOne();
} This adds the Person.AspNetUser property to the model as navigation property with a One-to-One association. Do not forget to generate a new migration. And check the Context Base Class property of the EF model - it should be Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext. Hope this helps!😉 |
I guess you can use |
@mmarinchenko Thank you!!! You are a saint, and a king! I had tried to use the ForeignKey("AspNetUserId") attribute on the custom AspNetUser property to get the context to understand the 1-1 relationship between those tables, but it gave me some strange constructor error, so I assumed it was not possible. The Fluent API approach did the trick. Even the database deployment didn't have to drop any data, and my new OnGetAsync method worked first try out of the box:
If you ever need a favor, I'm your guy. |
To support custom ASP.NET Core Identity scenario with EFDesigner some manual work has to be done.
Microsoft.AspNetCore.Identity
namespace:IdentityUser
IdentityRole
IdentityUserClaim<TKey>
IdentityUserRole<TKey>
IdentityRoleClaim<TKey>
IdentityUserLogin<TKey>
IdentityUserToken<TKey>
Note:
TKey
type parameter defaults tostring
type.Implement custom part of EFDesigner-generated DbContext class to define 7 respective DbSets and create model using partial
OnModelCreatedImpl()
method.Somehow inherit
IdentityDbContext<TUser,TRole,TKey,TUserClaim,TUserRole,TUserLogin,TRoleClaim,TUserToken>
type fromMicrosoft.AspNetCore.Identity.EntityFrameworkCore
namespace instead of defaultDbContext
fromMicrosoft.EntityFrameworkCore
.Note:
IdentityDbContext<>
in turn inheritsDbContext
.First 2 points are manual work because EFDesigner lacks:
string
type to be used as identity (actually not a strong requirement becauseInt64
may be used forTKey
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 :)The text was updated successfully, but these errors were encountered: