Successfully added
EF Core
by Roman
Setting Database Schema Name
To set a default schema name for your database context in Entity Framework using C#, follow these steps:
- Open your DbContext class.
- Override the
OnModelCreating
method. - Use
modelBuilder.HasDefaultSchema("YourSchemaName")
to configure the default schema.
Configure the default schema in OnModelCreating
method
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Configure default schema
modelBuilder.HasDefaultSchema("Sales");
}
This ensures that tables created by Entity Framework will use the specified schema (Sales
in this case).
For further reference, you can check out the discussion on c# - Setting schema name for DbContext - Stack Overflow
Referenced in:
Comments