預設結構描述Default Schema

注意

本節中的組態一般適用於關聯式資料庫。The configuration in this section is applicable to relational databases in general. 當您因共用 Microsoft.EntityFrameworkCore.Relational 套件而安裝關聯式資料庫提供者時,這裡顯示的擴充方法會變成可用。The extension methods shown here will become available when you install a relational database provider (due to the shared Microsoft.EntityFrameworkCore.Relational package).

預設結構描述是結構描述未明確設定為該物件,將會在建立物件的資料庫結構描述。The default schema is the database schema that objects will be created in if a schema is not explicitly configured for that object.

慣例Conventions

依照慣例,此資料庫提供者會選擇最適合的預設結構描述。By convention, the database provider will choose the most appropriate default schema. 例如,將會使用 Microsoft SQL Serverdbo結構描述和 SQLite 不會使用結構描述 (由於 SQLite 中不支援結構描述)。For example, Microsoft SQL Server will use the dbo schema and SQLite will not use a schema (since schemas are not supported in SQLite).

資料註釋Data Annotations

您可以設定使用資料註解的預設結構描述。You can not set the default schema using Data Annotations.

Fluent APIFluent API

您可以使用 Fluent API,來指定預設結構描述。You can use the Fluent API to specify a default schema.

class MyContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }

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