Skip to content

Commit 055ab79

Browse files
CopilotAndriySvyryd
andcommitted
Address feedback: restructure documentation, add EF 10 what's new note, fix samples
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
1 parent 00a9555 commit 055ab79

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

entity-framework/core/providers/sqlite/value-generation.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ By convention, numeric primary key columns that are configured to have their val
1515

1616
### Configuring AUTOINCREMENT
1717

18-
Starting with EF Core 10, you can explicitly configure a property to use SQLite AUTOINCREMENT using the new Fluent API:
18+
By convention, integer primary keys are automatically configured with AUTOINCREMENT when they don't have an explicitly assigned value. However, you may need to explicitly configure a property to use SQLite AUTOINCREMENT when the property has a value conversion from a non-integer type, or when overriding conventions:
19+
20+
[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs?name=SqliteAutoincrementWithValueConverter&highlight=6)]
21+
22+
Starting with EF Core 10, you can also use the new Fluent API:
1923

2024
```csharp
2125
protected override void OnModelCreating(ModelBuilder modelBuilder)
2226
{
23-
modelBuilder.Entity<Blog>()
27+
modelBuilder.Entity<BlogPost>()
2428
.Property(b => b.Id)
29+
.HasConversion<int>()
2530
.UseAutoincrement();
2631
}
2732
```
2833

29-
You can also configure AUTOINCREMENT using the annotation API:
30-
31-
[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs?name=SqliteAutoincrement&highlight=5)]
32-
3334
This is equivalent to using the more general value generation API:
3435

3536
```csharp
@@ -41,22 +42,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
4142
}
4243
```
4344

44-
By convention, integer primary keys are automatically configured with AUTOINCREMENT when they don't have an explicitly assigned value.
45-
46-
### Working with value converters
47-
48-
Starting with EF Core 10, SQLite AUTOINCREMENT works properly with value converters. Previously, properties with value converters weren't able to configure AUTOINCREMENT. For example:
49-
50-
[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs?name=SqliteAutoincrementWithValueConverter&highlight=6)]
51-
52-
In earlier versions of EF Core, this scenario would not work correctly and migrations would keep regenerating the same AlterColumn operation even without model changes.
53-
5445
## Disabling AUTOINCREMENT for default SQLite value generation
5546

5647
In some cases, you may want to disable AUTOINCREMENT and use SQLite's default value generation behavior instead. You can do this using the Metadata API:
5748

5849
[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs?name=SqliteValueGenerationStrategyNone&highlight=5)]
5950

51+
Starting with EF Core 10, you can also use the strongly-typed Metadata API:
52+
53+
```csharp
54+
protected override void OnModelCreating(ModelBuilder modelBuilder)
55+
{
56+
modelBuilder.Entity<Post>()
57+
.Property(p => p.Id)
58+
.Metadata.SetValueGenerationStrategy(SqliteValueGenerationStrategy.None);
59+
}
60+
```
61+
6062
Alternatively, you can disable value generation entirely:
6163

6264
```csharp
@@ -68,7 +70,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6870
}
6971
```
7072

71-
This means that it's up to the application to supply a value for the property before saving to the database.
73+
This means that it's up to the application to supply a value for the property before saving to the database. Note that this still won't disable the default value generation server-side, so non-EF usages could still get a generated value. To completely disable value generation the user can change the column type from `INTEGER` to `INT`.
7274

7375
## Migration behavior
7476

entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,14 @@ await context.Blogs.ExecuteUpdateAsync(s =>
628628

629629
Thanks to [@aradalvand](https://github.com/aradalvand) for proposing and pushing for this change (in [#32018](https://github.com/dotnet/efcore/issues/32018)).
630630

631+
<a name="sqlite"></a>
632+
633+
## SQLite
634+
635+
### Improved AUTOINCREMENT support
636+
637+
SQLite AUTOINCREMENT is now a first-class feature with full support through conventions and the Fluent API. Previously, properties with value converters couldn't configure AUTOINCREMENT and would cause false pending model change warnings.
638+
631639
<a name="other-improvements"></a>
632640

633641
## Other improvements

samples/core/Sqlite/ValueGeneration/Program.cs

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)