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

  • Home
  • SEARCH
  • 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 8427739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:51:39+00:00 2026-06-10T04:51:39+00:00

I am an ASP MVC 3 noobie who has done a few tutorials. Now

  • 0

I am an ASP MVC 3 noobie who has done a few tutorials. Now I’m trying to build a site. All of the tutorials on the microsoft website emphasize the code-first approach: you define your model with code and then create a datacontext and then the entity framework creates/manages the DB based on your code.

I set up an Employees class and a DataBaseContext class that inherits from DbContext. I added a connection string to Web.config connection string that successfully links DataBaseContext to an already existing empty DB on SQL server. EDIT= That was the problem. See my answer below

But when I try to run the Employees controller created thru scaffolding, I get this error

Invalid object name 'dbo.Employees'. 
Description: An unhandled exception occurred during the execution of...
Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Employees'.

I followed this post SqlException (0x80131904): Invalid object name 'dbo.Categories' and realized that if I create an employees table on the DB, this excpetion goes away (I get a new one saying that the column names are invalid).

But I thought the whole point of MVC 3 is that the framework will make the DB for you based on the code.

Maybe I need a line of code in the Global.asax Application_start() to create the database? Here is my application_start method:

Sub Application_Start()
    AreaRegistration.RegisterAllAreas()
    RegisterGlobalFilters(GlobalFilters.Filters)
    RegisterRoutes(RouteTable.Routes)
End Sub

Here is the code for Employee:

Public Class Employee

    Property EmployeeID As Integer
    Property First As String
    Property Last As String
    Property StartDate As DateTime
    Property VacationHours As Integer
    Property DateOfBirth As DateTime 'in case two employees have the same name

End Class

Here is the code for the DB context:

Imports System.Data.Entity

Public Class DatabaseContext
    Inherits DbContext

    Public Property Employee As DbSet(Of Employee)
    Public Property AnnualLeave As DbSet(Of AnnualLeave)

End Class

What am I missing?

  • 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-10T04:51:41+00:00Added an answer on June 10, 2026 at 4:51 am

    By default EF uses DropCreateDatabaseIfModelChanges<TContext> database initializer. Accordingly to the MSDN:

    An implementation of IDatabaseInitializer<TContext> that will delete, recreate, and optionally re-seed the database with data only if the model has changed since the database was created. This is achieved by writing a hash of the store model to the database when it is created and then comparing that hash with one generated from the current model.

    Since the database was created manually, EF can’t find the hash and decides do not perform any further initialization logic.

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

Sidebar

Related Questions

I have an ASP MVC 3 website that has a Feedback form and should
My ASP MVC (1.0) website has a default login page (based on OpenId -
My asp mvc site is not caching content or script files. How do I
Im new to asp.mvc. I'm trying to develop a portal to maintain employee data.
I have asp.mvc project. Currently routing is set to form following url's: site/school/45 site/school/45/courses
I have an ASP.MVC application which has a silverlight app inside. I want to
I have an ASP MVC 3 website which is used on the intranet. It
I have an ASP.MVC 2 web page and I have my authentication done like
Below is my asp mvc view. Note that it has a div which contains
Still new to ASP MVC development. Suppose I have a MusicController that has 2

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.