Introduction
CountrySeeder is an EF Core seeding tool that imports countries, states and cities into a PostgreSQL database from a large JSON file. It uses EFCore.BulkExtensions for fast bulk inserts and is configured from the command line or with environment variables.
Who it is for
Developers who need a complete country, state and city dataset in a PostgreSQL database, for example for address forms or location lookups.
Features
- Bulk insert with EFCore.BulkExtensions.
- Loads hierarchical country, state and city data from
countries_states_cities.json. - Supports the full JSON structure: coordinates, translations, time zones and more.
- Truncates existing data before seeding (with
CASCADEand identity reset). - Safe seeding: detects existing records and skips seeding unless forced.
- Configuration through a command-line argument or environment variables.
Project structure
CountrySeeder/
├── Program.cs → Entry point with the seeding logic
├── SeederDbContext.cs → EF Core DbContext
├── Entities/ → Country, State, City entities
├── Models/ → Models used to deserialize the JSON
└── countries_states_cities.json → JSON data source
Requirements
- .NET 8+
- PostgreSQL 12+
- EF Core Bulk Extensions
License
MIT License.
Links
- GitHub repository: github.com/Milvasoft/CountrySeeder
- Data source: dr5hn/countries-states-cities-database