Wednesday, October 2, 2013

Entity Framework: Specify a schema name

By default when you are using Entity Framework code first, the default ‘dbo’ schema is used. But what if you want to use a different schema?

There are multiple ways to do this.

Option 1: Use the ModelBuilder API

One way to change the schema is by using the modelbuilder API. To use this override the OnModelCreating option on your db and specify a schemaName using the Fluent API:

Option 2: Use attributes

Another option is the usage of Attributes on your model classes:

No comments: