EF Core 2.1. Use custom database schema for migration

.net-core asp.net-core c# entity-framework entity-framework-core

Question

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; }
}
1
1
6/1/2018 6:57:57 AM

Accepted Answer

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.

4
6/1/2018 7:11:17 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow