EntityType 'IdentityUserLogin' has no defined key. Define the key for this entity type


I am getting these errors when trying to create a merchant.

FlavorPing.Models.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.

FlavorPing.Models.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.

UserLogins: EntityType: EntitySet 'UserLogins' is based on type 'IdentityUserLogin' that has no keys defined.

UserRoles: EntityType: EntitySet 'UserRoles' is based on type 'IdentityUserRole' that has no keys defined."

Here is my merchant model:

namespace FlavorPing.Models
    public class Merchant
        //Meant to inherit identity.
        public string ApplicationUserId { get; set; }
        public virtual List<ApplicationUser> ApplicationUser { get; set; }

        public int MerchantID { get; set; }

        [Display(Name = "Business Name")]
        public string MerchantName { get; set; }

        [Display(Name = "Email")]
        public string email { get; set; }

        //need to create formatting here.
        [Display(Name = "Web Site Link")]
        public string website { get; set; }

        //public int MenuItemID { get; set; }

        public virtual List<MenuItem> MenuItems { get; set; }

        public virtual MerchantDetails MerchantDetails { get; set; }

        public ICollection<FollowerMenuItemMerchant> FollowerMenuItemMerchants { get; set; }

Here is the create controller for merchant, which is where I am getting the error:

// POST: Merchants/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
public ActionResult Create([Bind(Include = "MerchantID,MerchantName,email,website")] Merchant merchant)
    if (ModelState.IsValid)
        merchant.ApplicationUserId = User.Identity.GetUserId();
        return RedirectToAction("Index");

    return View(merchant);

Here is my DBContext:

namespace FlavorPing.Models
    public class FlavorPingContext : IdentityDbContext

        public FlavorPingContext()
            : base("name=FlavorPingContext")

        public System.Data.Entity.DbSet<FlavorPing.Models.Merchant> Merchants { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.MenuItem> MenuItems { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.MerchantDetails> MerchantDetails { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.Follower> Followers { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.FollowerMenuItemMerchant> FollowerMenuItemMerchants { get; set; }

        public DbSet<IdentityUserLogin> UserLogins { get; set; }
        public DbSet<IdentityUserClaim> UserClaims { get; set; }
        public DbSet<IdentityUserRole> UserRoles { get; set; }

        protected override void OnModelCreating(DbModelBuilder builder)
            // Primary keys
            builder.Entity<Follower>().HasKey(q => q.FollowerID);
            builder.Entity<MenuItem>().HasKey(q => q.MenuItemID);
            builder.Entity<Merchant>().HasKey(q => q.MerchantID);
            builder.Entity<FollowerMenuItemMerchant>().HasKey(q =>

            // Relationships
                .HasRequired(t => t.Follower)
                .WithMany(t => t.FollowerMenuItemMerchants)
                .HasForeignKey(t => t.FollowerID);

                .HasRequired(t => t.MenuItem)
                .WithMany(t => t.FollowerMenuItemMerchants)
                .HasForeignKey(t => t.MenuItemID);

            .HasRequired(t => t.Merchant)
            .WithMany(t => t.FollowerMenuItemMerchants)
            .HasForeignKey(t => t.MerchantID);



I am trying to follow the example (option2) in this link: EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType

I am trying Option 2 because I want to avoid having two DB's. But I am new to managing a DB so if you think I should do Option 3 please advise as to why, or if you see why I am getting this error please tell me why. Thanks in advance!

Ok I fixed my issue by adding this into my DBContext class.

    builder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
    builder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
    builder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });