Dear Csharpers,
I am customizing the default identity in a MVC asp.net core 6.0 project. I wanted to change the types of the Ids, thats why I inherited and have overriden the default IdentityUser, IdentityRoles na IdentityUserRoles as follows:
public class User : IdentityUser
{
public override Guid Id { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
......
......
//public ICollection
#nullable enable
public ICollection
}
public class Role : IdentityRole
{
public override Guid Id { get; set; }
public string Discriminator { get; set; }
}
public class UserRole : IdentityUserRole
{
public Guid Id {get; set;}
public override Guid UserId { get; set; }
public override Guid RoleId { get; set; }
}
Then I start the application and check, if the Database is empty => I seed an admin - create an user with new Guid for Id, then create and save Role with new Guid for RoleId, but after I try to create and add UserRole with the folowing code:
var userRole = new UserRole
{
Id = Guid.NewGuid(),
UserId = admin.Id,
RoleId = role.Id
};
....there comes this error:
"System.InvalidOperationException: 'The value of 'IdentityUserRole
Can anyone help me to solve this issue?
Abhishek YadavPosted Nov 19, 2022, 3:12 PM
deflne the web config here
IvanPosted Nov 19, 2022, 1:50 PM
I guess that I can't override Properties with other types but then I need to .ignore the property of identity old class, and then to set the new Id as primary key in mine ones? It doesn't allow me to that. It says I cant configure keys on derived class and "The key must be configured on the root type 'IdentityUser'." But I want to ignore the key there...!?