I have an MVC 5 Application with EF6, and I tried my first LINQ query in a SignalR Hub. It runs when I click on a button on a Test view page.
But I get an exception at the query:
This query is my first individual code action in the MVC5 template with individual User Accounts by the template. I only created the model classes before.
If it helps: The context I'm using is the template ApplicationDbContext:IdentityContext<ApplicationUser>
My "OnModelCreating" method looks like this:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Entity<Player>()
.HasMany(m => m.MilitaryAccess)
.WithMany();
modelBuilder.Entity<Player>()
.HasMany(m => m.FactionRelationship)
.WithMany();
base.OnModelCreating(modelBuilder);}
Thank you in advance!
I had the exact same problem with EF6.1.1 and my solution to the problem was quite simple...
Change:
protected ApplicationDbContext db = new ApplicationDbContext();
To:
protected ApplicationDbContext Db {get; set;}
public TestHub()
{
Db = new ApplicationDbContext();
}
But if you don't like this way, you can also use the LazySingleton Pattern approach.
Happy coding!