-
Notifications
You must be signed in to change notification settings - Fork 2k
Update SQLite AUTOINCREMENT documentation for EF Core 10 #5115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: live
Are you sure you want to change the base?
Conversation
Co-authored-by: AndriySvyryd <[email protected]>
} | ||
``` | ||
|
||
This means that it's up to the application to supply a value for the property before saving to the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Add a sentence saying 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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a sentence explaining that ValueGeneratedNever() still won't disable the default value generation server-side, so non-EF usages could still get a generated value. Also mentioned that to completely disable value generation the user can change the column type from INTEGER to INT. Commit: 055ab79
{ | ||
modelBuilder.Entity<Post>() | ||
.Property(p => p.Id) | ||
.HasAnnotation("Sqlite:ValueGenerationStrategy", "None"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.HasAnnotation("Sqlite:ValueGenerationStrategy", "None"); | |
.Metadata.SetValueGenerationStrategy(SqliteValueGenerationStrategy.None); |
@@ -0,0 +1,2 @@ | |||
// This file is for documentation samples only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Remove this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the Program.cs file as requested. Commit: 055ab79
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Reference 10.0.0-rc.1.25451.107
version, target net10.0
, add samples/global.json
specifying .NET 10 SDK version 10.0.100-rc.1.25451.107
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Do this and the other requested changes without verifying that it builds correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to reference EF 10 RC version (10.0.0-rc.1.25451.107), target net10.0, added samples/global.json specifying .NET 10 SDK version (10.0.100-rc.1.25451.107), and updated all samples to use the new UseAutoincrement() and SetValueGenerationStrategy APIs as requested. Commit: [short hash will be provided after commit]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to reference EF 10 RC version (10.0.0-rc.1.25451.107), target net10.0, added samples/global.json specifying .NET 10 SDK version (10.0.100-rc.1.25451.107), and updated all samples to use the new UseAutoincrement() and SetValueGenerationStrategy APIs as requested without build verification. Commit: 7c1aa86
modelBuilder.Entity<BlogPost>() | ||
.Property(b => b.Id) | ||
.HasConversion<int>() | ||
.HasAnnotation("Sqlite:Autoincrement", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Use the new API here and other places
…e, fix samples Co-authored-by: AndriySvyryd <[email protected]>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…eGenerationStrategy APIs Co-authored-by: AndriySvyryd <[email protected]>
@copilot Add a reference to |
|
||
## Additional Resources | ||
|
||
* [SQLite Value Generation](xref:core/providers/sqlite/value-generation) - Information about SQLite AUTOINCREMENT and value generation patterns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the "Additional Resources" section from the SQLite provider index page. Commit: c00dee1
|
||
### 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the convention text to clarify that AUTOINCREMENT applies to non-composite primary keys without foreign keys. Commit: c00dee1
}); | ||
``` | ||
|
||
This ensures that the AUTOINCREMENT feature is properly applied when the migration is executed against the SQLite database. No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Files should end with a single newline character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the file ending to have a single newline character. Commit: c00dee1
Co-authored-by: AndriySvyryd <[email protected]>
Added reference to core/providers/sqlite/value-generation from the main TOC under the SQLite provider section. Commit: [short hash will be provided after commit]
Added reference to core/providers/sqlite/value-generation from the main TOC under the SQLite provider section. The new documentation is now accessible through the navigation menu. Commit: eba15dc |
Starting with EF Core 10, you can also use the new Fluent API: | ||
|
||
```csharp | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<BlogPost>() | ||
.Property(b => b.Id) | ||
.HasConversion<int>() | ||
.UseAutoincrement(); | ||
} | ||
``` | ||
|
||
This is equivalent to using the more general value generation API: | ||
|
||
```csharp | ||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Blog>() | ||
.Property(b => b.Id) | ||
.ValueGeneratedOnAdd(); | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the redundant Fluent API example section from the value generation documentation. Commit: c00dee1
|
||
### 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Add a link to the new docs page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a link to the new SQLite value generation documentation page in the EF 10 what's new section. Commit: 1440b77
@@ -0,0 +1,26 @@ | |||
using Microsoft.EntityFrameworkCore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Remove this file, it's not referenced from anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the SqliteAutoincrement.cs file since it was not referenced anywhere in the documentation. Commit: 1440b77
public static implicit operator BlogId(int value) => new(value); | ||
} | ||
|
||
internal class SqliteAutoincrementWithValueConverterContext : DbContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Make this and the other added types public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the context classes public in SqliteAutoincrementWithValueConverter.cs and SqliteValueGenerationStrategyNone.cs. Commit: 1440b77
…ion text, remove fluent API section, fix file ending Co-authored-by: AndriySvyryd <[email protected]>
@copilot Replace the PR description with a nicely formatted summary |
…e file, make context classes public Co-authored-by: AndriySvyryd <[email protected]>
I don't have the ability to directly modify PR descriptions through my available tools. The PR description would need to be updated through the GitHub web interface or using GitHub API access. I can provide you with a nicely formatted summary that you could copy and paste to replace the current description if that would be helpful. |
Key Changes Made:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.