Using Entity Framework 4.3.1 CodeFirst and no luck getting migration or scripts to adhere to the scheme in which I want my tables to be in.
It seems that the default behavior (the one that I see no matter what I do) is to completely omit the schema from SQL that actually runs, causing the creation of tables in the default schema for the user running the migration or script.
My database administrators tell me that they cannot change my default schema because I am part of an AD group and not a local user, so I am changing the default schema for the user (often a recommended workaround) the script is not at all option.
I tried using annotations like this:
[Table("MyTable", Schema = "dbo")] public class MyTable { public int Id { get; set; } public string MyProp1 { get; set; } public string MyProp2 { get; set; } }
And I also tried using the free version of the same:
modelBuilder.Entity<YourType>().ToTable("MyTable", "dbo");
The result of the script (and migration) ignores the fact that I tried to specify a schema. The script looks like this:
CREATE TABLE [MyTable] ( [Id] [int] NOT NULL IDENTITY, [MyProp1] [nvarchar](max), [MyProp2] [nvarchar](max), CONSTRAINT [PK_MyTable] PRIMARY KEY ([Id]) )
If there should be [dbo] like this:
CREATE TABLE [dbo].[MyTable] ( [Id] [int] NOT NULL IDENTITY, [MyProp1] [nvarchar](max), [MyProp2] [nvarchar](max), CONSTRAINT [PK_MyTable] PRIMARY KEY ([Id]) )
Is anyone else lucky that the Entity Framework respects the schema? This behavior greatly kills our ability to use codefirst in general in our corporate environment.
Reminder: changing my user to use a different default scheme is not an option.