rustd / AspnetIdentitySample

476 stars 248 forks source link

Error in RoleAdmin Controller #33

Open tuppers360 opened 10 years ago

tuppers360 commented 10 years ago

Hi just implemented the example and get the following error in Details page of RolesAdmin:

CS1061: 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole' does not contain a definition for 'Users' and no extension method 'Users' accepting a first argument of type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole' could be found (are you missing a using directive or an assembly reference?)

Line 25: Line 26: Line 27: @Html.DisplayFor(modelItem => item.Users.UserName) Line 28: Line 29:

Funka commented 10 years ago

I'm running into the same error after updating all NuGet packages in the project.

I see what I think are two problems here. The first is that the item in var item in Model.Users seems to be an instance of IdentityUserRole, which doesn't have a "Users" property but we would expect for it to be the singular "User" here instead?

The second problem however, is that IdentityUserRole no longer seems to have a "User" property on it any more? Even though the MSDN documentation says there should be, the only properties I am seeing on this are UserID and RoleID. So, it's possible to use other means to get your instances of Role and User based on these ID's, it's just not as convenient.

What I've done to fix this for demo purposes is the change the line in question to the following:

@Html.DisplayFor(modelItem => item.UserId)

This just displays a list of GUIDs. But is fine for sample/demonstration purposes. Ideally, I would have expected "Role.Users" to give me a list of actual User objects instead of "UserRole" junction/entity objects, but that is another issue.

Funka commented 10 years ago

Note, this same problem (with same reasoning) exists in the UsersAdmin/Details.cshtml as well.