1

I have extended the IdentityUserRole by adding a foreign key column and now I am unable to Authorize or retrieve Roles information. Could please anyone help me in sorting out this issue.

My IdentityUserRole has a foreign key column from AspNetApplications table and the IdentityUserRole extension is as follow

public class AspNetUserRoles : IdentityUserRole
{
    [Key]
    public string ApplicationId { get; set; }

    [ForeignKey("ApplicationId")]
    public AspNetApplications AspNetApplications { get; set; }
}

After adding the migration I can see the foreign key column is created in AspNetUserRoles table. A screen shot of the table is as follow

enter image description here

Here I have two questions to ask

  1. Why it has created an auto Discriminator column and how I can remove it, if it has any overhead.
  2. What extra I have to do in order to get my Authorization and UserManager.GetRoles working as they were before doing this extension.

1 Answer 1

0

Discriminator column is about Table per Hierarchy (TPH).refer to this link What is a Discriminator column in ASP.NET Migrations?

About your authentication It should be something wrong with your dicriminator column.for example this code UserManager.GetRoles() has where clause for Discriminator filed to fetch data.

SELECT [Extent1].[Id] AS [Id], [Extent1].[Name] AS [Name] FROM [dbo].[Roles] AS [Extent1]
WHERE [Extent1].[Discriminator] = N'Role'

I think your where clause value in select command which send to database is different from what value you have in database

2
  • Thanks Arash. I didn't have any value in Discriminator column in my DB because I added the user directly from SQL. I am sure EF should have added the value if the user was created through code. By inserting my extended class name "AspNetUserRoles" in the Discriminator column of AspNetUserRoles table, it worked straight away. Sep 2, 2015 at 14:21
  • Learning Curve:yourwelcom. just be carefull when you adding record to your database don't use different class for adding records and fetching data from database.in that case you would have different discriminator
    – Arash
    Sep 2, 2015 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.