Aliaksei Zhukau
Aliaksei Zhukau

Reputation: 217

EF Core 2.1. Use custom database schema for migration

Today I moved a project from EF 2.0 to EF 2.1.

I want to change default database schema from dbo to MySchema

With EF Core 2.0 I used the following code:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.HasDefaultSchema("MySchema");
}

But I don't see .HasDefaultSchema method any more in EF Core 2.1.

How can you change default schema in EF Core 2.1?!

Note. As the quick solution used Table annotation with each entity model

[Table("MyEntities", Schema = "MySchema")]
public class MyEntity
{
    public int Id { get; set; }
}

Upvotes: 2

Views: 2533

Answers (1)

bommelding
bommelding

Reputation: 3037

It's an extension method and it is still listed in the 2.1 documentation

Note that you need the namespace Microsoft.EntityFrameworkCore and also make sure you have the package containing Microsoft.EntityFrameworkCore.Relational.dll

You may have missed the package when you were upgrading your project.

Upvotes: 5

Related Questions