DEV Community

Discussion on: Building a Service to Get a City Name from a ZIP Code in .NET Core

Collapse
 
dinsmoredesign profile image
Derek D • Edited

A few errors here:

  1. In your screenshot, you name the DB "zipcodes.db", then you have us run a migration, which creates a "cities.db", created from the Context.

  2. Startup.cs references "zipcodes.db", instead of the "cities.db" references in CityContext.

  3. If we change everything to "cities.db" (or "zipcodes.db") and then try to import the data from a CSV, you can't override the existing Cities table because DB Browser won't allow you to import the CSV into an existing table (the DB created from the migration) if it doesn't have the same number of matching columns. You need to add the "CityZip" column to the CSV file first.

  4. If we create a new DB from DB Browser and import the CSV into it, EF will connect, but throw an error because the "CityZip" column that EF adds doesn't exist.

  5. You name your table on import "zips", but your app is looking for the "Cities" table.

  6. Make sure to not have your DB open in DB Browser, or EF will report that the DB is Locked.

Once you change all occurrences of "zipcode.db" in your code to "cities.db", add the blank CityZip column to the CSV and import it into the DB created from the migration, all should run nicely ;) You don't need to manually create the DB, the migration will output the file for you.

Collapse
 
jeremycmorgan profile image
Jeremy Morgan

Thank you for the helpful feedback. I clearly missed a few things while putting it together. I have made corrections to the article and will have the project hosted up on GitHub soon so people can take a deeper look at it.

Thanks again!

Collapse
 
dinsmoredesign profile image
Derek D • Edited

No problem! I was looking for some resources to learn .NET Core (I'm a front end dev at a .NET shop) and I'd saved your tutorial a while back to try out. The errors actually forced me to learn the material better, since I had to do some troubleshooting to get everything running :P