Search code examples
entity-framework-4.1db-schema

entity framework code first and database user


We're running into a small problem deploying a web application to another environment. We created the application's db using Entity Framework Code First approach (db automatic created from Model). In this development environment, we are using integrated security and the tables are created under the dbo user. The tables are like
     [dbo].[myTable]

For our other environment, we are using username/password authentication for the DB. We scripted the tables and created them on the DB. So they are now named like
     [myDbUser].[myTable]

When running the application, we encounter always the problem
     Invalid object name 'dbo.myTable'.

Seems like the code is still trying to look for a dbo table, which is not present and thus fails.

Can anyone shed some light on this problem? Where does Entity Framework gets this dbo prefix from?

Thanks


Solution

  • Specify schema explicitly:

    [Table("Users", Schema = "dbo")]
    public class User { .. }
    

    Or specify default db schema for your user - 'dbo'