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 6336391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:02:53+00:00 2026-05-24T19:02:53+00:00

I am using Entity Framework 4.1 code first. I had a table in the

  • 0

I am using Entity Framework 4.1 code first.

I had a table in the database with the name MaritalStatus. I deleted it and created a new table in its place called MaritalStatuses. Whenever I try to get all the records from the table I get an error:

Invalid object name ‘dbo.MaritalStatus’.

The query that it is trying to execute is:

SELECT 
[Extent1].[Id] AS [Id], 
[Extent1].[Name] AS [Name], 
[Extent1].[IsActive] AS [IsActive]
FROM [dbo].[MaritalStatus] AS [Extent1]}

Why would it still be looking for table MaritalStatus that I deleted? Can it be possible that it is cached somewhere? I dropped the whole database and recreated it via scripts. Still no luck. Maybe it has an issue when it comes to the “es” part of the name?

Context class:

public class HefContext : DbContext
{
   public DbSet<Bank> Banks { get; set; }
   public DbSet<AccountType> AccountTypes { get; set; }
   public DbSet<MaritalStatus> MaritalStatuses { get; set; }
}

View model (with partial properties):

public class EditGrantApplicationViewModel
{
   public int Id { get; set; }
   public string EmployeeNumber { get; set; }
   public string FirstName { get; set; }
   public string LastName { get; set; }
   public int MaritalStatusId { get; set; }
   public IEnumerable<MaritalStatus> MaritalStatuses { get; set; }
   public int BankId { get; set; }
   public IEnumerable<Bank> Banks { get; set; }
   public int AccountTypeId { get; set; }
   public IEnumerable<AccountType> AccountTypes { get; set; }
}

Dropdown list in view for MaritalStatuses:

<td><label>Marital Status:</label> <span class="red">**</span></td>
<td>
   @Html.DropDownListFor(x => x.MaritalStatusId, new SelectList(Model.MaritalStatuses, "Id", "Name", Model.MaritalStatusId), "-- Select --")
   @Html.ValidationMessageFor(x => x.MaritalStatusId)
</td>

Controller:

public ActionResult Create()
{
   EditGrantApplicationViewModel viewModel = new EditGrantApplicationViewModel
   {
      MaritalStatuses = maritalStatusService.GetAll(),
      Banks = bankService.GetAll(),
      AccountTypes = accountTypeService.GetAll()
   };

   return View(viewModel);
}

Service:

public IEnumerable<MaritalStatus> GetAll()
{
   return maritalStatusRepository.GetAll();
}

Repository:

HefContext db = new HefContext();

public IEnumerable<MaritalStatus> GetAll()
{
   return db.MaritalStatuses;
}

Model class:

public class MaritalStatus
{
   public int Id { get; set; }
   public string Name { get; set; }
   public bool IsActive { get; set; }
}
  • 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-05-24T19:02:54+00:00Added an answer on May 24, 2026 at 7:02 pm

    You may have renamed the table in your database, but your Model class is still tied to the old name. You need to map the entity to the desired table name in the OnModelCreating method of your DbContext object

    public class HefContext : DbContext
    {
       public DbSet<Bank> Banks { get; set; }
       public DbSet<AccountType> AccountTypes { get; set; }
       public DbSet<MaritalStatus> MaritalStatuses { get; set; }
       protected override void OnModelCreating(DbModelBuilder modelBuilder)
       {
           modelBuilder.Entity<MaritalStatus>().ToTable("MaritalStatuses");
       }
    }
    

    Update:

    Apparently EF code first has some issues with the pluralization of some table names, such as Status. Out of curiosity I tested a few others and found several which also had this same issue.

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

Sidebar

Related Questions

I am using Entity Framework Code First to create a database table. My model
I am successfully creating database (SQL Ce) using Entity Framework Code First approach (C#-WPF).
When creating a database using Entity Framework code-first, a lot of the database model
I'm using Entity Framework code first to manage a database backstore for my users.
I'm using Entity Framework Code First to generated my database, so I have an
I'm using Entity Framework Code-First with POCOs for my database interaction. I have a
How to declare a one to one relationship using Entity Framework 4 Code First
I have been using Entity Framework CTP with Code-First as in this tutorial by
I'm using code-first in entity-framework 4, Entity Framework Feature CTP 3 Is it possible
I have a small MVC 3 app using Entity Framework Code First and use

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.