https://github.com/tomashubelbauer/ef-sqlite
Reproducing an issue with migrations and table rebuilds I had in EF Core SQLite
https://github.com/tomashubelbauer/ef-sqlite
ef ef-core entity-framework entity-framework-core migrations sqlite
Last synced: 2 months ago
JSON representation
Reproducing an issue with migrations and table rebuilds I had in EF Core SQLite
- Host: GitHub
- URL: https://github.com/tomashubelbauer/ef-sqlite
- Owner: TomasHubelbauer
- Created: 2019-12-08T20:22:47.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-04-14T20:14:06.000Z (about 4 years ago)
- Last Synced: 2025-06-03T11:32:16.075Z (about 1 year ago)
- Topics: ef, ef-core, entity-framework, entity-framework-core, migrations, sqlite
- Language: C#
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EF Core SQLite
SQLite has an EF Core provider, which is great, because SQLite is a RDBMS which
can run in-process unlike SQL Server, Postgres etc. but still has on-disk
persistence unlike say the in-memory provider. Unfortunately, in SQLite, a lot
of schema operations require table rebuilds, which are not supported in EF Core:
https://github.com/aspnet/EntityFrameworkCore/issues/329
This repository demonstrates the problem.
- `dotnet new console`
- `dotnet add package Microsoft.EntityFrameworkCore.Sqlite`
- Create `AppDbContext` with a single `DbSet` property of items
- Create the `Item` model class with an ID and a name
- Override `OnConfiguring` in `AppDbContext` to connect to SQLite
- Reset the database and then insert, save and retrieve an item for a test
- Use `EnsureDeleted` following by `EnsureCreated` to carry out the reset
- `dotnet run` to verify everything works
- Reference the design package for EF tools:
`dotnet add package Microsoft.EntityFrameworkCore.Design`
- Scaffold the initial migration:
`dotnet ef migrations add ScaffoldInitialSchema`
- Create a new entity - `User` and reference it in an `Item` and vice-versa 1:N
- Create a new `DbSet` for the user entity
- Expand the demo code to create the user with the item and persist both at once
- Scaffold a new migration capturing the new entity and relationships:
`dotnet ef migrations add AddUserEntityAndItemReference`
- Replace the database reset with a `Migrate` call to force automated migration
- Or not replace but follow up?
## To-Do
### Retest now that SQLite table rebuilds have landed
https://github.com/aspnet/EntityFrameworkCore/issues/329