SQLite EF Core 資料庫提供者的限制SQLite EF Core Database Provider Limitations

SQLite 提供者有幾項移轉限制。The SQLite provider has a number of migrations limitations. 這些限制大部分都是基礎的 SQLite 資料庫引擎中的限制的結果,並不是特別針對 EF。Most of these limitations are a result of limitations in the underlying SQLite database engine and are not specific to EF.

模型限制Modeling limitations

(Entity Framework 的關聯式資料庫提供者所共用) 的通用關聯式程式庫會定義 Api 模型化概念通用於大部分的關聯式資料庫引擎。The common relational library (shared by Entity Framework relational database providers) defines APIs for modelling concepts that are common to most relational database engines. SQLite 提供者不支援幾個這些概念。A couple of these concepts are not supported by the SQLite provider.

  • 結構描述Schemas
  • 序列Sequences

移轉限制Migrations limitations

SQLite 資料庫引擎不支援結構描述作業大部分的其他關聯式資料庫所支援的數量。The SQLite database engine does not support a number of schema operations that are supported by the majority of other relational databases. 如果您嘗試將其中一個不支援的作業套用至 SQLite 資料庫則NotSupportedException就會擲回。If you attempt to apply one of the unsupported operations to a SQLite database then a NotSupportedException will be thrown.

運算Operation 支援?Supported? 需要版本Requires version
AddColumnAddColumn 1.01.0
AddForeignKeyAddForeignKey
AddPrimaryKeyAddPrimaryKey
AddUniqueConstraintAddUniqueConstraint
AlterColumnAlterColumn
CreateIndexCreateIndex 1.01.0
CreateTableCreateTable 1.01.0
DropColumnDropColumn
DropForeignKeyDropForeignKey
DropIndexDropIndex 1.01.0
DropPrimaryKeyDropPrimaryKey
DropTableDropTable 1.01.0
DropUniqueConstraintDropUniqueConstraint
RenameColumnRenameColumn
RenameIndexRenameIndex 2.12.1
RenameTableRenameTable 1.01.0
EnsureSchemaEnsureSchema ✔ (無作業)✔ (no-op) 2.02.0
DropSchemaDropSchema ✔ (無作業)✔ (no-op) 2.02.0
InsertInsert 2.02.0
更新Update 2.02.0
刪除Delete 2.02.0

移轉限制的因應措施Migrations limitations workaround

您可以因應措施是一些手動撰寫的程式碼在您移轉來執行資料表中的這些限制的重建。You can workaround some of these limitations by manually writing code in your migrations to perform a table rebuild. 重新命名現有的資料表、 建立新的資料表、 將資料複製到新的資料表,以及卸除舊的資料表,則牽涉到重建的資料表。A table rebuild involves renaming the existing table, creating a new table, copying data to the new table, and dropping the old table. 您必須使用Sql(string)來執行這些步驟的某些方法。You will need to use the Sql(string) method to perform some of these steps.

請參閱進行其他類型的資料表結構描述變更SQLite 文件以取得詳細資料中。See Making Other Kinds Of Table Schema Changes in the SQLite documentation for more details.

在未來,EF 可能支援這些作業的一些使用在幕後的資料表重建方法。In the future, EF may support some of these operations by using the table rebuild approach under the covers. 您可以追蹤這項功能,在我們的 GitHub 專案You can track this feature on our GitHub project.