Aspnetcore.docs: Fix Add IdentityUser POCO Navigation Properties sample

Created on 18 Dec 2017  Â·  20Comments  Â·  Source: dotnet/AspNetCore.Docs

_From @postb99 on December 17, 2017 21:49_

Please fix the "Add IdentityUser POCO Navigation Properties" example code on this page register entities: in my case I have derivated types for IdentityUser, IdentityRole, IdentityUserRole, IdentityUserToken, IdentityUserLogin (they have int primary/foreign key), with "long" naming of navigation properties (User has a navigation property named "UserRoles" instead of "Roles"...)

Then my user has UserRoles, UserTokens, UserLogins navigation properties, my Role has UserRoles navigation property.

I end up with correct initial migration with these mapping declarations: in addition to the example code, I declare the one to many relationship from Role to UserRole, so that "RoleId1" column isn't created.

modelBuilder_.Entity<User>().HasMany(e => e.UserRoles).WithOne().HasForeignKey(e => e.UserId).IsRequired().OnDelete(DeleteBehavior.Cascade);
modelBuilder_.Entity<User>().HasMany(e => e.UserRoles).WithOne().HasForeignKey(e => e.RoleId).IsRequired().OnDelete(DeleteBehavior.Cascade);
modelBuilder_.Entity<Role>().HasMany(e => e.UserRoles).WithOne().HasForeignKey(e => e.RoleId).IsRequired().OnDelete(DeleteBehavior.Cascade);
modelBuilder_.Entity<User>().HasMany(e => e.UserLogins).WithOne().HasForeignKey(e => e.UserId).IsRequired().OnDelete(DeleteBehavior.Cascade);
modelBuilder_.Entity<User>().HasMany(e => e.UserTokens).WithOne().HasForeignKey(e => e.UserId).IsRequired().OnDelete(DeleteBehavior.Cascade);

_Copied from original issue: aspnet/Identity#1533_

Help wanted P1 P2 doc-bug

All 20 comments

After afterthought, the correct indication would be that the entity mapping should be explicitly redefined for every entity that references the "TKey" column, either as a PK or as a FK. It wasn't obvious for me at first sight, being a learner. Thanks.

@postb99 any chance you could help out with the PR?

Yes, you're right,I can handle it.

Le 19 déc. 2017 05:55, "Rick Anderson" notifications@github.com a écrit :

@postb99 https://github.com/postb99 any chance you could help out with
the PR?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aspnet/Docs/issues/5028#issuecomment-352639661, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKl_Yal2jiPQ6wqiIJKSjiLb-jhDHe7ks5tB0HFgaJpZM4RF5Zu
.

@ajcvickers I'm looking for some guidance on how to update the code snippet in question.

@scottaddie It's on my list to get to this. Is it critical this is done now?

@ajcvickers We do consider this critical. This is a high-traffic document, and several customers have commented on this particular code snippet.

@ajcvickers I think in the next week would be OK.

@Rick-Anderson @scottaddie That's going to require some significant re-shuffling of priorities, since I need to spend significant time getting up to speed learning this area before I will be able to make any meaningful comments. Even if I start now, I don't know I will have anything concrete by next week.

I think we can wait a month - will that work?

@HaoK would you be able to consult? @blowdart who else could help?

@Rick-Anderson A month makes it easier.

For navigation properties, i'm basically a more inefficient route to @ajcvickers :)

@ajcvickers Revisiting this issue, as customers continue to ask about it. Any updates to provide?

@ajcvickers would you be able to schedule this sometime in the next 8 weeks? The topic has 15K PVM from very important customers.

@Rick-Anderson Closing down 2.1 is currently the priority, so it depends how that goes. Identity/docs issues are currently next on my list, although VS/NuGet issues could end up bumping this.

@ajcvickers scheduling for end of Q3

@ajcvickers Feel free to assign us issues from https://github.com/aspnet/EntityFrameworkCore/issues to free up some of your time.

@Rick-Anderson My intention was that you could update this taking the bits you want from the most comprehensive document that I created. Do you want me to do that part also?

@scottaddie can you do this? Ping @ajcvickers if you run into problems.

@danroth27 please review/set priority.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danroth27 picture danroth27  Â·  3Comments

sonichanxiao picture sonichanxiao  Â·  3Comments

aaron-bozit picture aaron-bozit  Â·  3Comments

madelson picture madelson  Â·  3Comments

serpent5 picture serpent5  Â·  3Comments