Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin' requires a key to be defined

$
0
0

I'm trying to write a .net core 1 web app. I have separated out the layers and all was working fine until I introducedIdentity into the bag.

Down in my repository layer I have a IServiceCollection extension where I'm adding identity:

publicstaticclassRepositoryCollectionExtensions{publicstaticIServiceCollectionRegisterRepositoryServices(thisIServiceCollection services){
            services.AddDbContext<VisualJobsDbContext>();

            services.AddIdentity<ApplicationUser,IdentityRole<int>>(
                config => config.User.RequireUniqueEmail=true).AddEntityFrameworkStores<VisualJobsDbContext,int>().AddDefaultTokenProviders();

            services.AddScoped<IRecruiterRepository,RecruiterRepository>();return services;}}

My Context class takes the form:

publicpartialclassVisualJobsDbContext:IdentityDbContext<ApplicationUser,IdentityRole<int>,int>{privateIConfigurationRoot _config;publicVisualJobsDbContext(){}publicVisualJobsDbContext(IConfigurationRoot config,DbContextOptions<VisualJobsDbContext> options):base(options){
            _config = config;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilder optionsBuilder){base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseSqlServer(@_config["ConnectionStrings:VisualJobsContextConnection"]);}protectedoverridevoidOnModelCreating(ModelBuilder modelBuilder){.......

I then have my specific repository that uses a generic repository:

publicclassRecruiterRepository:GenericRepository<VisualJobsDbContext,Agent>,IRecruiterRepository{privateVisualJobsDbContext _context;publicRecruiterRepository(VisualJobsDbContext context):base(context){
            _context = context;}.....

Where Agent is a class from my Models.

The Generic repository takes the form:

publicabstractclassGenericRepository<C,T>:IGenericRepository<T>where T :classwhere C :IdentityDbContext<ApplicationUser,IdentityRole<int>,int>,new(){private C _entities =new C();privateVisualJobsDbContext context;privateDbSet<T> dbSet;publicGenericRepository(VisualJobsDbContext context){this.context = context;this.dbSet = context.Set<T>();}.....

It errors when trying to set this.dbSet = context.Set<T>();  if a Look in context all my model classes are in there including Agent. If I look on any of the objects they all have the error above set against them.

in the top layer in the MVC startup.cs file in the configure method I call app.UseIdentity(); before app.UseMvc


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>