We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Having this model
public class Book { public int ID { get; set; } public string Name { get; set; } } public class BookContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("Data Source=.\\SQLExpress;Initial Catalog=Books;Integrated Security=True"); base.OnConfiguring(optionsBuilder); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Book>().Property(x => x.ID).ValueGeneratedNever(); base.OnModelCreating(modelBuilder); } public DbSet<Book> Books { get; set; } }
in which Book.ID must be set manually:
Book.ID
ID
ValueGeneratedNever()
//modelBuilder.Entity<Book>().Property(x => x.ID).ValueGeneratedNever();
The generated migration for setting the ID to IDENTITY is as follows:
public partial class Set_Book_ID_As_Identity : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterColumn<int>( name: "ID", table: "Books", nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.AlterColumn<int>( name: "ID", table: "Books", nullable: false); } }
resulting in this SQL
ALTER TABLE [Books] ALTER COLUMN [ID] int NOT NULL;
which doesn't set the ID to auto-increment identity.
To generate a migration like this
migrationBuilder.DropColumn( name: "ID", table: "Books"); migrationBuilder.AddColumn<int>( name: "ID", table: "Books", nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
EF Core version: 1.0 Operating system: Windows 10 x64 Visual Studio version: VS 2015 Update 3
The text was updated successfully, but these errors were encountered:
Dupe of #2100 (tracked as part of #329)
Sorry, something went wrong.
No branches or pull requests
Steps to reproduce
Having this model
in which
Book.ID
must be set manually:ID
property to be IDENTITY by commentingValueGeneratedNever()
lineThe issue
The generated migration for setting the ID to IDENTITY is as follows:
resulting in this SQL
which doesn't set the
ID
to auto-increment identity.Expected behavior
To generate a migration like this
Further technical details
EF Core version: 1.0
Operating system: Windows 10 x64
Visual Studio version: VS 2015 Update 3
The text was updated successfully, but these errors were encountered: