Change schema name in Entity Framework Core
October 18, 2022 by Anuraj
dotnet dotnetcore efcore
This post is about how to change schema name in EF Core. By default when we are running EF Core migrations, EF Core will create tables in the default dbo
schema. We can change it with fluent API and using attributes.
In the fluent API, we can configure the schema with HasDefaultSchema
method, which will apply the schema for all the tables. And if you want only for specific tables, we can use the ToTable
method overload. Here is pseudo code.
And here is the implementation using the ToTable data annotations attributes.
Using these two ways we will be able to customize the EF Core database schema.
Happy Programming.
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub