Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?
Tag : chash , By : amorican
Date : March 29 2020, 07:55 AM
Does that help I've been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try in my MVC 5 application and I recieved this error when trying to update my database: , You might have to add something like the following to OnModelCreating modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
|
GetTable in ApplicationDbContext : IdentityDbContext<ApplicationUser>
Tag : chash , By : Bjørn Lyngwa
Date : March 29 2020, 07:55 AM
around this issue Since you're using EF6 queries are automatically compiled regardless of the .net framework the code is running against. The link you provided in your question is dated from 2009 when it made sense to pre-compile queries.
|
MVC5 Referencing ApplicationDbContext : IdentityDbContext<ApplicationUser>
Tag : chash , By : dbarbot
Date : March 29 2020, 07:55 AM
Hope that helps You are still referencing the old namespace and class. You need to change it to the new context. And since you are already including the using RecreationalServicesTicketingSystem.Models then all you need to do is remove the old referenced namespace. using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using RecreationalServicesTicketingSystem.Models; // this is the namespace that has the new context
using System.Collections.Generic;
internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext> //References the new one now
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(ApplicationDbContext context)//References the new one now
{...}
//...other code removed for prebity
}
|
ApplicationDbContext.OnModelCreating(ModelBuilder): no suitable method found to override
Tag : chash , By : jaredsmiller
Date : March 29 2020, 07:55 AM
Hope this helps According to the documentation, the OnModelCreating method takes a DbModelBuilder, not a ModelBuilder.
|
ApplicationDbContext.OnModelCreating() in .Net Standard 2.0 has MissingMethodException
Date : March 29 2020, 07:55 AM
I wish this helpful for you So, I have a solution for my problem: use Microsoft.EntityFrameworkCore.SqlServer version 2.2.6 (NOT 3.1.1 even though its supposed to work with .net standard 2.0...)
|