VisualStudio Code and .NET Core 2.2 migration

I have experienced a weird problem today. My application has been throwing Entity Framework exceptions, which were saying that database which I am trying to open has unmatched column. It was about column called “Order”, which exists in source code of a class which is wired with table. Yep – I have added that column recently, but I added needed migration and applied it on database to which I am trying to connect. I even see applied migration in “__EFMigrationsHistory” table. What the heck?

Only clue I had was that it happens only in Visual Studio Code, while not in VS 2017. I decided to review local VS Code configuration files then. What I have found there?

 

{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/MyMilionDollarIdea.App/bin/Debug/netcoreapp2.1/MyMilionDollarIdea.App.dll",
"args": [],
"cwd": "${workspaceFolder}/MyMilionDollarIdea.App",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

Bingo! Path to the project which is tarting after hitting F5 (Debug->Start Debugging) leads to .NET Core 2.1 app path. And I have updated my application to .NET Core 2.2!

The exception from Entity Framework was simply misleading. Yes, in .NET Core 2.1 version of my app “Order” column was not available, and entities also didn’t have such. When VS was trying to run my application then it was trying to map newer database structure to entity which was older, without “Order” property. So I got the exception.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website