Search code examples
entity-frameworkcsvparsingtype-conversiondbset

Conversion failed error when it shouldn't be trying to convert anything


Message "Conversion failed when converting the nvarchar value '\"United States\"' to data type int."

I use entity framework for data access to a SQL DB.

It is set as a string in my table and it is set as a string in my entity.

This is happening in a CSV parsing programme, when trying to call the save changes method of the DbSet.

Any ideas why this is happening and how to fix this problem?


Solution

  • Are you sure you havent made changes on your database? If so, run UpdateDatabase

    in your PM console. If not, check the parsing of the CSV columns. Maybe you're mapping them wrong.