Menu
Cutty
  • Chryslers
  • Lutherie
  • YLSNED
  • About
Cutty

SqLite Auto-increment fields in Entity Framework

Posted on December 11, 2019December 11, 2019 by Iain 'Cutty' Carlin

By default, Scaffolding a table with an auto-increment field adds:

.ValueGeneratedNever();

To the field in the Model Builder. This will cause an automatic value NOT to be generated. This needs to be removed.

Also, we need to add:

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int? TemplateId { get; set; }

To the item – and ensure it is a nullable int. https://docs.microsoft.com/en-us/ef/core/modeling/generated-properties

Recent Posts

  • 2024 was the best year for our solar system
  • Books I read in 2024
  • Books I read in 2023
  • Happy New Year 2024
  • Lawson – A life in words and music

Categories

  • Chryslers (1)
  • Cutty's Blog (12)
  • Lutherie (38)
  • You Learn Something New Every Day (43)
©2025 Cutty | Powered by Superb Themes