Using Entity Framework 6 with Multiple DB Schemas but using One DBContext
In addition to the responce of Gert Arnold, you can also use Table attribute in your entity:
using System.ComponentModel.DataAnnotations.Schema;
[Table("t_Department", Schema = "school")]
public class Department
{
public int Id { get; set; }
public string Name { get; set; }
}
You can map each table to its own schema by fluent mapping only. In your DbContext
subtype you should override OnModelCreating
(if you haven't done so already) and add statements like this:
modelBuilder.Entity<Department>()
.ToTable("t_Department", "school");
Entities that you don't map like this explicitly will be placed in the default dbo
schema, or you can provide your own default by
modelBuilder.HasDefaultSchema("sales");
(summarized from here)