I have created a test project where I am playing around with .NET Core 2.2 and Identity Framework 2.0.
I have successfully created a project and adjusted some fields so that I understand how the data is parsed from the View
to the Controller
to the Stores
.
I have been looking at customizing the database so that a user will also contain a ReferralID
to test some stuff out, this ReferralID
is an integer.
What I did is I extended the IdentityUser
with this custom property and made a custom version for every Identity Option.
public class ApplicationUsers : IdentityUser
{
public int? ReferralID { get; set; } = null;
}
I also added it to the database in the tables that were generated but now the application is throwing an error:
CLR property 'ReferralID' cannot be added to entity type 'IdentityUser' because it is declared on the CLR type 'ApplicationUsers'
I have unfortunately not been able to find/understand what is wrong, it seems that something is wrong in the ModelBuilder, I have not touched the model builder and it was auto generated by using a scaffolder Scaffold-DbContext "Data Source=(localdb)\mssqllocaldb;Initial Catalog=CoreTest;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -Context GolfScoresContext -OutputDir Models -DataAnnotations -Project WebApi -Force
What step did I miss? Or can I not add custom properties to an IdentityUser? I have seen people struggling with this and adding [NotMapped]
to ApplicationUsers
but then I think my property will not get saved.