Skip to content Skip to sidebar Skip to footer

Change Entity Framework Database Schema Map After Using Code First

I've finished building my blog using EF and Code First. EF was running against my local SQL Express instance, with [DBO] schema. Now i want to publish the blog, and i have done the

Solution 1:

EF will use dbo schema if you didn't configure the schema explicitly through data annotations or fluent API.

[Table("MyTable", "MySchema")]
publicclassMyEntity
{

}

Or

modelBuidler.Entity<MyEntity>().ToTable("MyTable", "MySchema");

Solution 2:

Just for searchers: I am just working with EF5 .NET4.5, and

[Table("MyTable", "MySchema")]

does not work. Even if VS2012 shows there is an overload which takes 2 parameters, on build it gives the error: 'System.ComponentModel.DataAnnotations.Schema.TableAttribute' does not contain a constructor that takes 2 arguments.

But the code mapping works just fine.

Post a Comment for "Change Entity Framework Database Schema Map After Using Code First"