SQLite EF Core-Datenbank-Anbieter-EinschränkungenSQLite EF Core Database Provider Limitations
Der SQLite-Anbieter hat eine Reihe von Migrations Einschränkungen.The SQLite provider has a number of migrations limitations. Die meisten dieser Einschränkungen sind das Ergebnis von Einschränkungen in der zugrunde liegenden SQLite-Datenbank-Engine und nicht spezifisch für EF.Most of these limitations are a result of limitations in the underlying SQLite database engine and are not specific to EF.
ModellierungseinschränkungenModeling limitations
Die gemeinsame relationale Bibliothek (die von Entity Framework relationalen Datenbankanbietern gemeinsam verwendet wird) definiert APIs zum Modellieren von Konzepten, die für die meisten relationalen Daten Bank EnginesThe common relational library (shared by Entity Framework relational database providers) defines APIs for modelling concepts that are common to most relational database engines. Einige dieser Konzepte werden vom SQLite-Anbieter nicht unterstützt.A couple of these concepts are not supported by the SQLite provider.
- SchemasSchemas
- SequenzenSequences
AbfrageeinschränkungenQuery limitations
SQLite unterstützt die folgenden Datentypen nicht nativ.SQLite doesn't natively support the following data types. EF Core können Werte dieser Typen lesen und schreiben, und Abfragen auf Gleichheit ( where e.Property == value
) werden ebenfalls unterstützt.EF Core can read and write values of these types, and querying for equality (where e.Property == value
) is also supported. Für andere Vorgänge, wie z. b. Vergleich und Reihenfolge, ist jedoch eine Auswertung auf dem Client erforderlich.Other operations, however, like comparison and ordering will require evaluation on the client.
- DateTimeOffsetDateTimeOffset
- DecimalDecimal
- TimeSpanTimeSpan
- UInt64UInt64
Anstelle von DateTimeOffset
wird empfohlen, DateTime-Werte zu verwenden.Instead of DateTimeOffset
, we recommend using DateTime values. Wenn Sie mehrere Zeitzonen verarbeiten, empfiehlt es sich, die Werte vor dem Speichern in die UTC zu umrechnen und dann wieder in die entsprechende Zeitzone umzuwandeln.When handling multiple time zones, we recommend converting the values to UTC before saving and then converting back to the appropriate time zone.
Der- Decimal
Typ bietet eine hohe Genauigkeit.The Decimal
type provides a high level of precision. Wenn Sie diese Genauigkeits Stufe nicht benötigen, empfiehlt sich stattdessen die Verwendung von Double.If you don't need that level of precision, however, we recommend using double instead. Sie können einen Wert Konverter verwenden, um in ihren Klassen weiterhin Decimal zu verwenden.You can use a value converter to continue using decimal in your classes.
modelBuilder.Entity<MyEntity>()
.Property(e => e.DecimalProperty)
.HasConversion<double>();
Migrations EinschränkungenMigrations limitations
Die SQLite-Datenbank-Engine unterstützt keine Reihe von Schema Vorgängen, die von den meisten anderen relationalen Datenbanken unterstützt werden.The SQLite database engine does not support a number of schema operations that are supported by the majority of other relational databases. Wenn Sie versuchen, einen der nicht unterstützten Vorgänge auf eine SQLite-Datenbank anzuwenden, NotSupportedException
wird eine ausgelöst.If you attempt to apply one of the unsupported operations to a SQLite database then a NotSupportedException
will be thrown.
Es wird versucht, eine Neuerstellung auszuführen, um bestimmte Vorgänge auszuführen.A rebuild will be attempted in order to perform certain operations. Neubuilds sind nur für Daten Bank Artefakte möglich, die Teil Ihres EF Core Modells sind.Rebuilds are only possible for database artifacts that are part of your EF Core model. Wenn ein Daten Bank Element nicht Teil des Modells ist (z. b., wenn es in einer Migration manuell erstellt wurde), NotSupportedException
wird immer noch eine ausgelöst.If a database artifact isn't part of the model--for example, if it was created manually inside a migration--then a NotSupportedException
is still thrown.
VorgangOperation | Unterstützt?Supported? | Erfordert VersionRequires version |
---|---|---|
AddcheckeinschränkungAddCheckConstraint | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
AddColumnAddColumn | ✔✔ | |
AddfremdnkeyAddForeignKey | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
AddprimarykeyAddPrimaryKey | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
AddUniqueConstraintAddUniqueConstraint | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
AlterColumnAlterColumn | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
CreateIndexCreateIndex | ✔✔ | |
CreateTableCreateTable | ✔✔ | |
Dropcheck-EinschränkungDropCheckConstraint | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
DropColumnDropColumn | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
DropfremdnkeyDropForeignKey | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
DropIndexDropIndex | ✔✔ | |
DropprimarykeyDropPrimaryKey | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
DropTableDropTable | ✔✔ | |
DropuniqueconstraintDropUniqueConstraint | ✔ (neu erstellen)✔ (rebuild) | 5.05.0 |
RenamecolumnRenameColumn | ✔✔ | 2.22.2 |
RenameingedexRenameIndex | ✔ (neu erstellen)✔ (rebuild) | |
RenameTableRenameTable | ✔✔ | |
EnsureschemaEnsureSchema | ✔ (No-OP)✔ (no-op) | |
DropSchemaDropSchema | ✔ (No-OP)✔ (no-op) | |
EinfügenInsert | ✔✔ | |
AktualisierenUpdate | ✔✔ | |
LöschenDelete | ✔✔ |
Problem Umgehung der Migrations EinschränkungenMigrations limitations workaround
Sie können einige dieser Einschränkungen umgehen, indem Sie Code in ihren Migrationen manuell schreiben, um eine Neuerstellung durchzuführen.You can workaround some of these limitations by manually writing code in your migrations to perform a rebuild. Tabellen neubuilds umfassen das Erstellen einer neuen Tabelle, das Kopieren von Daten in die neue Tabelle, das Löschen der alten Tabelle und das Umbenennen der neuen Tabelle.Table rebuilds involve creating a new table, copying data to the new table, dropping the old table, renaming the new table. Sie müssen die-Methode verwenden Sql(string)
, um einige dieser Schritte auszuführen.You will need to use the Sql(string)
method to perform some of these steps.
Weitere Informationen finden Sie unter vornehmen anderer Arten von Tabellen Schema Änderungen in der SQLite-Dokumentation.See Making Other Kinds Of Table Schema Changes in the SQLite documentation for more details.
Einschränkungen für idempotente SkriptsIdempotent script limitations
Anders als andere Datenbanken enthält SQLite keine prozedurale Sprache.Unlike other databases, SQLite doesn't include a procedural language. Aus diesem Grund gibt es keine Möglichkeit, die von den idempotenten Migrations Skripts benötigte if-then-Logik zu generieren.Because of this, there is no way to generate the if-then logic required by the idempotent migration scripts.
Wenn Sie wissen, dass die letzte Migration auf eine Datenbank angewendet wurde, können Sie ein Skript aus dieser Migration zur neuesten Migration generieren.If you know the last migration applied to a database, you can generate a script from that migration to the latest migration.
dotnet ef migrations script CurrentMigration
Andernfalls wird empfohlen, dotnet ef database update
zum Anwenden von Migrationen zu verwenden.Otherwise, we recommend using dotnet ef database update
to apply migrations. Ab EF Core 5,0 können Sie die Datenbankdatei angeben, wenn Sie den Befehl ausführen.Starting in EF Core 5.0, you can specify the database file when running the command.
dotnet ef database update --connection "Data Source=My.db"