-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support 64-bit Identity seed values #24840
Comments
@josephmoresena please try configuring the identity seed as explained in the docs, with UseIdentityColumn. Avoid manipulating metadata directly as you're doing above - that's usually not needed. |
UseIdentityColumn only admits Int32 input parameters. |
Ah, I see now - you're right; this doesn't look like it's possible at the moment without lots of hacking around. You should be able to work around this by altering the identity seed by using raw SQL in your migrations (as demonstrated here). |
When using "Add-Migration" in Package Manager Console, I still get an exception:
|
@schuettecarsten the code below works for me with EF 6.0.0-preview.7.21378.4, producing the following CREATE TABLE: CREATE TABLE [Blogs] (
[Id] bigint NOT NULL IDENTITY(9223372036854775807, 1),
[Name] nvarchar(max) NULL,
CONSTRAINT [PK_Blogs] PRIMARY KEY ([Id])
); Doing the same via migrations works as well. Double-check that you're using the latest preview, and if the problem persists, please open a new issue with a minimal code sample. Attempted reproawait using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
static ILoggerFactory ContextLoggerFactory
=> LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0")
.EnableSensitiveDataLogging()
.UseLoggerFactory(ContextLoggerFactory);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>().Property(b => b.Id).UseIdentityColumn(long.MaxValue);
}
}
public class Blog
{
public long Id { get; set; }
public string Name { get; set; }
} |
Okay, this was caused by my existing migrations. I had to replace all |
Thanks @schuettecarsten. I filed #25589 to track this. |
I'm trying to create a project with Code First with this entity:
I want to create an identity for that property with Int64.MinValue as seed. In OnModelCreating method im trying to set that value:
But when i'm building migration I getting the following error:
EF Core version: 5.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 5.0
Operating system:
IDE: Visual Studio 2019 16.9.4
The text was updated successfully, but these errors were encountered: