Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:20:11+00:00 2026-06-17T08:20:11+00:00

I keep getting error when I try to access a model from an edit

  • 0

I keep getting error when I try to access a model from an edit or details action.

The model backing the ‘InjuriesContext’ context has changed since the
database was created. Consider using Code First Migrations to update
the database (http://go.microsoft.com/fwlink/?LinkId=238269).

First I tried adding a migration even though I was sure I hadn’t changed anything. Still recieved the same error after an update-database.

Then I removed all the migrations and the database and started a clean database with an inital migration and update. Same error. Nothing was changed.

Model is:

public class InjuriesContext : DbContext
    {
        public InjuriesContext()
            : base("DBCon")
        {
        }

        public DbSet<Patient> Patients { get; set; }

        public DbSet<Injury> Injuries { get; set; }
    }

    public class Injury
    {
        public int Id { get; set; }
        public string Type { get; set; }
        public int PatientId { get; set; }
    }

Here is controller —

public ActionResult Edit(int id = 0)
        {
            Injury injury = db.Injuries.Find(id);
            if (injury == null)
            {
                return HttpNotFound();
            }
            return View(injury);
        }

It errors on the injuries.find. I do not have any injuries entered so I expect it to return a 404 like my other controllers but it doesn’t like something about this. The only difference between this and my other models is the y to ies for plural. Does Entity Framework not handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:20:12+00:00Added an answer on June 17, 2026 at 8:20 am

    It turns out my issue was with multiple contexts. I thought you had to create a separate context for each model class. Apparently Entity Framework needs one context. I went through and created a class for my context and put all my DBsets in that class.

        public class ProjContexts : DbContext
        {
             public ProjContexts()
                : base("ProjDBCon")
            {
            }
    
            public DbSet<Patient> Patients { get; set; }
            public DbSet<PreHosp> PreHosps { get; set; }
            public DbSet<UserProfile> UserProfiles { get; set; }
            public DbSet<Injury> Injuries { get; set; }
    
        }
    }
    

    Then I removed all the migrations as per this post and enabled the migrations again did an add migration and update then I got the expected result.

    Bottom Line— Don’t have multiple context classes in your project. Not sure if this is possible but after changing the above everything is working as expected. Not sure why it was working when I had two separate contexts and added the third? Maybe because they had foreign keys with one another?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error when I try and use an MS Access database
I keep getting this error when i try to access forms that calls WCF
I keep getting this error when I try to commit a group of executed
I keep getting this error when I try to call Find() public void findTxt(string
I keep getting this error when I try to install a package: Download error
Hi guys I keep getting an error no image selected when I try and
I keep getting a 'List does not exist' error whenever I try and use
I keep getting 21002 'java.lang.NullPointerException' errors from Apple when I try to test my
I am getting an error when I try to refresh access token: 400 Bad
When I try to remove index.php and access controller: mysite.com/admin I keep getting Internal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.