3. Configure Entity Framework
This step is optional, however it gives you amazing features allowing to work with your data directly from visual studio code editor and search tables by their class names. It is recommended to first check if all data has been correctly loaded without entity framework mappings, because this step is little bit more complicated due to fact that every project is completely different and it is difficult for me to test every possible scenario, but I will try to accomplish this.
This step is separated because it is good to know in case of error if it is related with this step or the previous one(especially if you are configuring this extension for the first time). To select dbContext you have to open 'Configuration' modal window again(from VS menu or DatabaseView). Then in 'EF Context' column of selected database you need to choose correct class of entity framework model for this database and save configuration.
After few seconds you will get following error message ‘Missing specialized DbContext constructor’
, click ‘Details’ button and you will see similar code snippet. You can copy this snippet, then open your db context class and paste it there.
What is happening right now is very important to understand. Because reloading entity framework class mappings needs to create instance of your db context to extract those mappings, but I don’t want to create your ef context with default constructor, because there might be some logic or strategy to drop and recreate database etc. I don’t want to do any of this. Therefore you need to have constructor overload like the one in the snippet, so it can call this specific constructor with connection string from selected database and logic which you know is correct for this step. Please have in mind that provided snippet is only a hint of how it should look like, you may need to perform some changes to this code for example you might not be inheriting directly from entity framework db context but your own base class which don’t have constructor with string parameter. As you can see there is also a NOTE section which you might need to uncomment if you encounter a mentioned error.
After adding specialized constructor, we need to build our solution because we need new version of assembly with modified db context. This step is only required if we are using entity framework db context mappings. Now we can open configuration window again and reload data.
That’s it! As you can see all data has been loaded and you are ready to work with Netverest tools. It was very fast process, moreover you need to perform it only once per solution, so next time when you open solution everything will be already configured.
This process is almost exactly the same, only difference is in how you define specialized construcor. In this case you need to derive from Ef Core model class and override method, which allows to provide custom connection string. You will get more details and example in error message, when reloading ef context without this constructor.