1

I have never encountered this error before:

Server Error in '/' Application.

One or more validation errors were detected during model generation:

wc2018.DAL.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
wc2018.DAL.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.

I have have never had any trouble with Identity/Role/Users/Logins before but when I try to register a new user through my web app, this is what I get.

Here is my Context:

using Microsoft.AspNet.Identity.EntityFramework;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using wc2018.Models;

namespace wc2018.DAL
{
    public class WC2018Context : IdentityDbContext<ApplicationUser>
    {
        public WC2018Context() : base("WC2018Context", throwIfV1Schema: false)
        {
       }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }

    public static WC2018Context Create()
    {
        return new WC2018Context();
    }

    public System.Data.Entity.DbSet<wc2018.Models.Team> Teams { get; set; }
    }
}

Seeder:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using wc2018.Models;
using wc2018.DAL;

namespace wc2018.Models
{
    public class WC2018Initialiser : DropCreateDatabaseAlways<WC2018Context> { 
        protected override void Seed(WC2018Context context) { 
            context.Teams.Add(new Team { Name = "David's Mob", Owner = "DS" });
            context.Teams.Add(new Team { Name = "Christo's Minions", Owner = "CJ The Winner" }); 
            context.SaveChanges(); 
            base.Seed(context); 
        } 
    }
}

Can anyone point me in the right direction, as to how to resolve please?

dstewart101
  • 1,084
  • 1
  • 16
  • 38

1 Answers1

1

Hi I too had this same error long ago , by putting this one line base.OnModelCreating(modelBuilder); in OnModelCreating method , solved my problem .

your changed code:

  protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
          base.OnModelCreating(modelBuilder);

        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

    }

Useful links: https://stackoverflow.com/a/34786782/3397630 , No key Defined' errors

Hope it will solve your problem too.

Thanks

Karthik

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12