https://github.com/dorssel/dotnet-ef-sqlite-timestamp
Extension for Entity Framework (EF) Core 8.0 that adds support for SQLite row versioning ([Timestamp] attribute).
https://github.com/dorssel/dotnet-ef-sqlite-timestamp
dotnet entity-framework-core sqlite
Last synced: 5 months ago
JSON representation
Extension for Entity Framework (EF) Core 8.0 that adds support for SQLite row versioning ([Timestamp] attribute).
- Host: GitHub
- URL: https://github.com/dorssel/dotnet-ef-sqlite-timestamp
- Owner: dorssel
- License: mit
- Created: 2024-02-28T19:53:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-11T23:32:24.000Z (over 1 year ago)
- Last Synced: 2024-05-01T18:01:59.439Z (about 1 year ago)
- Topics: dotnet, entity-framework-core, sqlite
- Language: C#
- Homepage:
- Size: 68.4 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# dotnet-ef-sqlite-timestamp
[](https://github.com/dorssel/dotnet-ef-sqlite-timestamp/actions?query=workflow%3ABuild+branch%3Amain)
[](https://github.com/dorssel/dotnet-ef-sqlite-timestamp/actions?query=workflow%3ACodeQL+branch%3Amain)
[](https://github.com/dorssel/dotnet-ef-sqlite-timestamp/actions?query=workflow%3ALint+branch%3Amain)
[](https://codecov.io/gh/dorssel/dotnet-ef-sqlite-timestamp)
[](https://api.reuse.software/info/github.com/dorssel/dotnet-ef-sqlite-timestamp)
[](https://www.nuget.org/packages/Dorssel.EntityFrameworkCore.Sqlite.Timestamp)Extension for Entity Framework (EF) Core 8.0 (or higher) that adds support for SQLite row versioning (`[Timestamp]` attribute).
The implementation is for AnyCPU, and works on all platforms.
# Usage
Add a package reference to your project for
[`Dorssel.EntityFrameworkCore.Sqlite.Timestamp`](https://www.nuget.org/packages/Dorssel.EntityFrameworkCore.Sqlite.Timestamp),
next to an explicit reference to the required version of SQLite.For EF Core 8:
```diff
+
```For EF Core 9:
```diff
+
```> [!NOTE]
> It is not recommended to solely rely on the transitive dependency on `Microsoft.EntityFrameworkCore.Sqlite`,
> as that would use the version at the time `Dorssel.EntityFrameworkCore.Sqlite.Timestamp` was built
> instead of the latest one. Therefore, always add an explicit package reference for `Microsoft.EntityFrameworkCore.Sqlite`
> in your project as well.In your `DbContext` derived class modify the following:
```diff
+ using Dorssel.EntityFrameworkCore;protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlite($"Data Source={DbPath}")
+ .UseSqliteTimestamp();
}
```This is all you need to support row versioning with SQLite, including support for migrations.
See [Native database-generated concurrency tokens](https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=data-annotations#native-database-generated-concurrency-tokens);
except now you can ignore the part that says it isn't supported with SQLite!## Example
See the Example project for a demonstration using .NET 9 & EF Core 9.
# NuGet package
The released [NuGet package](https://www.nuget.org/packages/Dorssel.EntityFrameworkCore.Sqlite.Timestamp)
and the .NET assemblies contained therein have the following properties:- [Strong Naming](https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/strong-naming)
- [SourceLink](https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink)
- [IntelliSense](https://learn.microsoft.com/en-us/visualstudio/ide/using-intellisense)
- [Authenticode](https://learn.microsoft.com/en-us/windows/win32/seccrypto/time-stamping-authenticode-signatures#a-brief-introduction-to-authenticode)