From 08116472827c07d408511fda62a4c5571c295b30 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 26 Sep 2025 20:15:12 +0000 Subject: [PATCH 1/7] Initial plan From 00a95551bf55b32286952d9f4828cf1e7aca1dad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 26 Sep 2025 20:24:57 +0000 Subject: [PATCH 2/7] Add SQLite value generation documentation and samples Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../core/providers/sqlite/index.md | 4 + .../core/providers/sqlite/value-generation.md | 92 +++++++++++++++++++ .../core/Sqlite/ValueGeneration/Program.cs | 2 + .../ValueGeneration/SqliteAutoincrement.cs | 26 ++++++ .../SqliteAutoincrementWithValueConverter.cs | 36 ++++++++ .../SqliteValueGeneration.csproj | 14 +++ .../SqliteValueGenerationStrategyNone.cs | 26 ++++++ 7 files changed, 200 insertions(+) create mode 100644 entity-framework/core/providers/sqlite/value-generation.md create mode 100644 samples/core/Sqlite/ValueGeneration/Program.cs create mode 100644 samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs create mode 100644 samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs create mode 100644 samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj create mode 100644 samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs diff --git a/entity-framework/core/providers/sqlite/index.md b/entity-framework/core/providers/sqlite/index.md index 756a6e4a0e..a8cf0aa664 100644 --- a/entity-framework/core/providers/sqlite/index.md +++ b/entity-framework/core/providers/sqlite/index.md @@ -34,3 +34,7 @@ Install-Package Microsoft.EntityFrameworkCore.Sqlite ## Limitations See [SQLite Limitations](xref:core/providers/sqlite/limitations) for some important limitations of the SQLite provider. + +## Additional Resources + +* [SQLite Value Generation](xref:core/providers/sqlite/value-generation) - Information about SQLite AUTOINCREMENT and value generation patterns. diff --git a/entity-framework/core/providers/sqlite/value-generation.md b/entity-framework/core/providers/sqlite/value-generation.md new file mode 100644 index 0000000000..96abc959e1 --- /dev/null +++ b/entity-framework/core/providers/sqlite/value-generation.md @@ -0,0 +1,92 @@ +--- +title: SQLite Database Provider - Value Generation - EF Core +description: Value Generation Patterns Specific to the SQLite Entity Framework Core Database Provider +author: AndriySvyryd +ms.date: 09/26/2025 +uid: core/providers/sqlite/value-generation +--- +# SQLite Value Generation + +This page details value generation configuration and patterns that are specific to the SQLite provider. It's recommended to first read [the general page on value generation](xref:core/modeling/generated-properties). + +## AUTOINCREMENT columns + +By convention, numeric primary key columns that are configured to have their values generated on add are set up with SQLite's AUTOINCREMENT feature. Starting with EF Core 10, SQLite AUTOINCREMENT is a first-class feature with full support through conventions and the Fluent API. + +### Configuring AUTOINCREMENT + +Starting with EF Core 10, you can explicitly configure a property to use SQLite AUTOINCREMENT using the new Fluent API: + +```csharp +protected override void OnModelCreating(ModelBuilder modelBuilder) +{ + modelBuilder.Entity() + .Property(b => b.Id) + .UseAutoincrement(); +} +``` + +You can also configure AUTOINCREMENT using the annotation API: + +[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs?name=SqliteAutoincrement&highlight=5)] + +This is equivalent to using the more general value generation API: + +```csharp +protected override void OnModelCreating(ModelBuilder modelBuilder) +{ + modelBuilder.Entity() + .Property(b => b.Id) + .ValueGeneratedOnAdd(); +} +``` + +By convention, integer primary keys are automatically configured with AUTOINCREMENT when they don't have an explicitly assigned value. + +### Working with value converters + +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: + +[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs?name=SqliteAutoincrementWithValueConverter&highlight=6)] + +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. + +## Disabling AUTOINCREMENT for default SQLite value generation + +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: + +[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs?name=SqliteValueGenerationStrategyNone&highlight=5)] + +Alternatively, you can disable value generation entirely: + +```csharp +protected override void OnModelCreating(ModelBuilder modelBuilder) +{ + modelBuilder.Entity() + .Property(b => b.Id) + .ValueGeneratedNever(); +} +``` + +This means that it's up to the application to supply a value for the property before saving to the database. + +## Migration behavior + +When EF Core generates migrations for SQLite AUTOINCREMENT columns, the generated migration will include the `Sqlite:Autoincrement` annotation: + +```csharp +migrationBuilder.CreateTable( + name: "Blogs", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Title = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Blogs", x => x.Id); + }); +``` + +This ensures that the AUTOINCREMENT feature is properly applied when the migration is executed against the SQLite database. \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/Program.cs b/samples/core/Sqlite/ValueGeneration/Program.cs new file mode 100644 index 0000000000..73c21ff764 --- /dev/null +++ b/samples/core/Sqlite/ValueGeneration/Program.cs @@ -0,0 +1,2 @@ +// This file is for documentation samples only. +// The actual implementation code is in the individual sample files. \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs new file mode 100644 index 0000000000..0560d57f53 --- /dev/null +++ b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; + +namespace EFCore.Sqlite.ValueGeneration; + +internal class SqliteAutoincrementContext : DbContext +{ + public DbSet Blogs { get; set; } + + #region SqliteAutoincrement + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .Property(b => b.Id) + .HasAnnotation("Sqlite:Autoincrement", true); + } + #endregion + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseSqlite("Data Source=sample.db"); +} + +public class Blog +{ + public int Id { get; set; } + public string Title { get; set; } +} \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs new file mode 100644 index 0000000000..b64fcaa7ca --- /dev/null +++ b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore; + +namespace EFCore.Sqlite.ValueGeneration; + +public readonly struct BlogId +{ + public BlogId(int value) => Value = value; + public int Value { get; } + + public static implicit operator int(BlogId id) => id.Value; + public static implicit operator BlogId(int value) => new(value); +} + +internal class SqliteAutoincrementWithValueConverterContext : DbContext +{ + public DbSet Blogs { get; set; } + + #region SqliteAutoincrementWithValueConverter + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .Property(b => b.Id) + .HasConversion() + .HasAnnotation("Sqlite:Autoincrement", true); + } + #endregion + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseSqlite("Data Source=sample.db"); +} + +public class BlogPost +{ + public BlogId Id { get; set; } + public string Title { get; set; } +} \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj b/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj new file mode 100644 index 0000000000..27a21dd4dc --- /dev/null +++ b/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + disable + Library + + + + + + + \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs b/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs new file mode 100644 index 0000000000..7ddba71d04 --- /dev/null +++ b/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; + +namespace EFCore.Sqlite.ValueGeneration; + +internal class SqliteValueGenerationStrategyNoneContext : DbContext +{ + public DbSet Posts { get; set; } + + #region SqliteValueGenerationStrategyNone + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .Property(p => p.Id) + .HasAnnotation("Sqlite:ValueGenerationStrategy", "None"); + } + #endregion + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseSqlite("Data Source=sample.db"); +} + +public class Post +{ + public int Id { get; set; } + public string Content { get; set; } +} \ No newline at end of file From 055ab793a205027b1951b5f6f9c7839f4aafedfe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Sep 2025 17:45:29 +0000 Subject: [PATCH 3/7] Address feedback: restructure documentation, add EF 10 what's new note, fix samples Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../core/providers/sqlite/value-generation.md | 36 ++++++++++--------- .../core/what-is-new/ef-core-10.0/whatsnew.md | 8 +++++ .../core/Sqlite/ValueGeneration/Program.cs | 2 -- 3 files changed, 27 insertions(+), 19 deletions(-) delete mode 100644 samples/core/Sqlite/ValueGeneration/Program.cs diff --git a/entity-framework/core/providers/sqlite/value-generation.md b/entity-framework/core/providers/sqlite/value-generation.md index 96abc959e1..5eff464b0b 100644 --- a/entity-framework/core/providers/sqlite/value-generation.md +++ b/entity-framework/core/providers/sqlite/value-generation.md @@ -15,21 +15,22 @@ By convention, numeric primary key columns that are configured to have their val ### Configuring AUTOINCREMENT -Starting with EF Core 10, you can explicitly configure a property to use SQLite AUTOINCREMENT using the new Fluent API: +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: + +[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs?name=SqliteAutoincrementWithValueConverter&highlight=6)] + +Starting with EF Core 10, you can also use the new Fluent API: ```csharp protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity() + modelBuilder.Entity() .Property(b => b.Id) + .HasConversion() .UseAutoincrement(); } ``` -You can also configure AUTOINCREMENT using the annotation API: - -[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs?name=SqliteAutoincrement&highlight=5)] - This is equivalent to using the more general value generation API: ```csharp @@ -41,22 +42,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } ``` -By convention, integer primary keys are automatically configured with AUTOINCREMENT when they don't have an explicitly assigned value. - -### Working with value converters - -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: - -[!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs?name=SqliteAutoincrementWithValueConverter&highlight=6)] - -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. - ## Disabling AUTOINCREMENT for default SQLite value generation 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: [!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs?name=SqliteValueGenerationStrategyNone&highlight=5)] +Starting with EF Core 10, you can also use the strongly-typed Metadata API: + +```csharp +protected override void OnModelCreating(ModelBuilder modelBuilder) +{ + modelBuilder.Entity() + .Property(p => p.Id) + .Metadata.SetValueGenerationStrategy(SqliteValueGenerationStrategy.None); +} +``` + Alternatively, you can disable value generation entirely: ```csharp @@ -68,7 +70,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } ``` -This means that it's up to the application to supply a value for the property before saving to the database. +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`. ## Migration behavior diff --git a/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md index 5b84bddb7d..7346131578 100644 --- a/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md @@ -628,6 +628,14 @@ await context.Blogs.ExecuteUpdateAsync(s => Thanks to [@aradalvand](https://github.com/aradalvand) for proposing and pushing for this change (in [#32018](https://github.com/dotnet/efcore/issues/32018)). + + +## SQLite + +### Improved AUTOINCREMENT support + +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. + ## Other improvements diff --git a/samples/core/Sqlite/ValueGeneration/Program.cs b/samples/core/Sqlite/ValueGeneration/Program.cs deleted file mode 100644 index 73c21ff764..0000000000 --- a/samples/core/Sqlite/ValueGeneration/Program.cs +++ /dev/null @@ -1,2 +0,0 @@ -// This file is for documentation samples only. -// The actual implementation code is in the individual sample files. \ No newline at end of file From 7c1aa86c4e6a2ad43a1c3961012da47961143c9f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Sep 2025 19:50:18 +0000 Subject: [PATCH 4/7] Update to EF 10 RC version and use new UseAutoincrement() and SetValueGenerationStrategy APIs Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs | 2 +- .../ValueGeneration/SqliteAutoincrementWithValueConverter.cs | 2 +- .../core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj | 4 ++-- .../ValueGeneration/SqliteValueGenerationStrategyNone.cs | 3 ++- samples/global.json | 5 +++++ 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 samples/global.json diff --git a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs index 0560d57f53..cdd259d8b0 100644 --- a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs +++ b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs @@ -11,7 +11,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .Property(b => b.Id) - .HasAnnotation("Sqlite:Autoincrement", true); + .UseAutoincrement(); } #endregion diff --git a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs index b64fcaa7ca..6e67342807 100644 --- a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs +++ b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs @@ -21,7 +21,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .Property(b => b.Id) .HasConversion() - .HasAnnotation("Sqlite:Autoincrement", true); + .UseAutoincrement(); } #endregion diff --git a/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj b/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj index 27a21dd4dc..6798d6ed9c 100644 --- a/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj +++ b/samples/core/Sqlite/ValueGeneration/SqliteValueGeneration.csproj @@ -1,14 +1,14 @@ - net8.0 + net10.0 enable disable Library - + \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs b/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs index 7ddba71d04..4d65d278b0 100644 --- a/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs +++ b/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Sqlite.Metadata; namespace EFCore.Sqlite.ValueGeneration; @@ -11,7 +12,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .Property(p => p.Id) - .HasAnnotation("Sqlite:ValueGenerationStrategy", "None"); + .Metadata.SetValueGenerationStrategy(SqliteValueGenerationStrategy.None); } #endregion diff --git a/samples/global.json b/samples/global.json new file mode 100644 index 0000000000..be4942c34f --- /dev/null +++ b/samples/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "10.0.100-rc.1.25451.107" + } +} \ No newline at end of file From eba15dc14c2e4a62799727fd6090658f2b3c8de0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Sep 2025 20:02:54 +0000 Subject: [PATCH 5/7] Add SQLite value generation to TOC Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- entity-framework/toc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entity-framework/toc.yml b/entity-framework/toc.yml index 12b1bb3055..529e1a2800 100644 --- a/entity-framework/toc.yml +++ b/entity-framework/toc.yml @@ -423,6 +423,8 @@ href: core/providers/sqlite/limitations.md - name: Function mappings href: core/providers/sqlite/functions.md + - name: Value generation + href: core/providers/sqlite/value-generation.md - name: Spatial data displayName: GIS href: core/providers/sqlite/spatial.md From c00dee14c04f3f371be7dfa7706b696b585659ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Sep 2025 20:06:52 +0000 Subject: [PATCH 6/7] Address feedback: remove additional resources section, update convention text, remove fluent API section, fix file ending Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../core/providers/sqlite/index.md | 4 --- .../core/providers/sqlite/value-generation.md | 27 ++----------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/entity-framework/core/providers/sqlite/index.md b/entity-framework/core/providers/sqlite/index.md index a8cf0aa664..756a6e4a0e 100644 --- a/entity-framework/core/providers/sqlite/index.md +++ b/entity-framework/core/providers/sqlite/index.md @@ -34,7 +34,3 @@ Install-Package Microsoft.EntityFrameworkCore.Sqlite ## Limitations See [SQLite Limitations](xref:core/providers/sqlite/limitations) for some important limitations of the SQLite provider. - -## Additional Resources - -* [SQLite Value Generation](xref:core/providers/sqlite/value-generation) - Information about SQLite AUTOINCREMENT and value generation patterns. diff --git a/entity-framework/core/providers/sqlite/value-generation.md b/entity-framework/core/providers/sqlite/value-generation.md index 5eff464b0b..a9190c3f57 100644 --- a/entity-framework/core/providers/sqlite/value-generation.md +++ b/entity-framework/core/providers/sqlite/value-generation.md @@ -15,33 +15,10 @@ By convention, numeric primary key columns that are configured to have their val ### Configuring AUTOINCREMENT -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: +By convention, integer primary keys are automatically configured with AUTOINCREMENT when they are not composite and don't have a foreign key on them. 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: [!code-csharp[Main](../../../../samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs?name=SqliteAutoincrementWithValueConverter&highlight=6)] -Starting with EF Core 10, you can also use the new Fluent API: - -```csharp -protected override void OnModelCreating(ModelBuilder modelBuilder) -{ - modelBuilder.Entity() - .Property(b => b.Id) - .HasConversion() - .UseAutoincrement(); -} -``` - -This is equivalent to using the more general value generation API: - -```csharp -protected override void OnModelCreating(ModelBuilder modelBuilder) -{ - modelBuilder.Entity() - .Property(b => b.Id) - .ValueGeneratedOnAdd(); -} -``` - ## Disabling AUTOINCREMENT for default SQLite value generation 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: @@ -91,4 +68,4 @@ migrationBuilder.CreateTable( }); ``` -This ensures that the AUTOINCREMENT feature is properly applied when the migration is executed against the SQLite database. \ No newline at end of file +This ensures that the AUTOINCREMENT feature is properly applied when the migration is executed against the SQLite database. From 1440b7721dcbc1955d62c4cb64669a01515b9acc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Sep 2025 20:10:11 +0000 Subject: [PATCH 7/7] Address feedback: add link to docs in what's new, remove unused sample file, make context classes public Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../core/what-is-new/ef-core-10.0/whatsnew.md | 2 ++ .../ValueGeneration/SqliteAutoincrement.cs | 26 ------------------- .../SqliteAutoincrementWithValueConverter.cs | 2 +- .../SqliteValueGenerationStrategyNone.cs | 2 +- 4 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs diff --git a/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md index 7346131578..ccbde80e7b 100644 --- a/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md @@ -636,6 +636,8 @@ Thanks to [@aradalvand](https://github.com/aradalvand) for proposing and pushing 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. +For more information, see [SQLite Value Generation](xref:core/providers/sqlite/value-generation). + ## Other improvements diff --git a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs deleted file mode 100644 index cdd259d8b0..0000000000 --- a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrement.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace EFCore.Sqlite.ValueGeneration; - -internal class SqliteAutoincrementContext : DbContext -{ - public DbSet Blogs { get; set; } - - #region SqliteAutoincrement - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .Property(b => b.Id) - .UseAutoincrement(); - } - #endregion - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder.UseSqlite("Data Source=sample.db"); -} - -public class Blog -{ - public int Id { get; set; } - public string Title { get; set; } -} \ No newline at end of file diff --git a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs index 6e67342807..e5cae61860 100644 --- a/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs +++ b/samples/core/Sqlite/ValueGeneration/SqliteAutoincrementWithValueConverter.cs @@ -11,7 +11,7 @@ public readonly struct BlogId public static implicit operator BlogId(int value) => new(value); } -internal class SqliteAutoincrementWithValueConverterContext : DbContext +public class SqliteAutoincrementWithValueConverterContext : DbContext { public DbSet Blogs { get; set; } diff --git a/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs b/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs index 4d65d278b0..35711cbe5d 100644 --- a/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs +++ b/samples/core/Sqlite/ValueGeneration/SqliteValueGenerationStrategyNone.cs @@ -3,7 +3,7 @@ namespace EFCore.Sqlite.ValueGeneration; -internal class SqliteValueGenerationStrategyNoneContext : DbContext +public class SqliteValueGenerationStrategyNoneContext : DbContext { public DbSet Posts { get; set; }