Visual Studio 2019 continues to look for the previous DbContext even after replacing it with a new one - entity-framework-core

Disclaimer: I am posting a self-answer to this. Even though it's something that's rather unusual to do, hopefully someone will benefit from reading this.
I recently replaced my original Entity Framework Core DbContext with a new one because I renamed the database (among other things). Let's call the original one OriginalDbContext and NewDbContext for convenience.
The table structure itself remained unchanged.
Naturally, I had to replace all instances of OriginalDbContext with NewDbContext. I was expecting that, once I did that, it would simply compile (since I didn't make any database changes other than replace OriginalDbContext with NewDbContext). However, even after I did that, I got numerous error messages stating to the effect that OldDbContext did not have a definition for my table clases.
I searched all files in my solution for any reference to OriginalDbContext and found none. I even deleted OriginalDbContext.cs entirely (including in version control).
Why would it continue to "look for" OriginalDbContext even though I verified that it was removed from all of my .cs files?

I finally did a "Find All" on the entire directory. It turns out that the only place that referred to OriginalDbContext was one of my publish profiles (which did not appear when I searched only in the solution). I deleted the profile and was able to compile again.
I guess the broader lesson here is that there could be references to your DbContext class that do not appear in your code base and may not even show up if you do a "Find All" on the entire solution.
Worse yet, when I double-clicked the original error messages, it made it appear like the errors were coming from my code base.

Related

What is the correct/best way to remove customizations from Microsoft Dynamics 365?

I've been experimenting with D365 in a virtual machine.
Not everything I've done has worked or has otherwise been desirable.
When I go to do other things, I sometimes can't save because of name conflicts.
Removing the directory for the models from C:\AOSService\PackageLocalDirectory did not resolve this, and in some context, I even have the possibility to add to the model which does not exist (which of course results in other errors).
Also, for example, when looking at a MainAccount's form, I still see fields which I previously created, despite having deleted both the model and the project... Is there some way I can remove these?

is watchman notifies for deleted files?

I tried to find in the documentation and I did not find indication.
I read the win32 watch code (because I am familiar with the API and it seems it does not).
Tracking for file deletion is extremely convoluted on windows, because the API provides the file names "randomly" mangled and if the file is not there anymore to resolve the real name "long path" it is hard to say what was the original.
I have implemented such thing for my previous company, with preserving the current state of files and reconciling the list of files for every directory that changes were happening inside. It worked well.
My question is: did I miss it and watchman notifies for deleted files? And if it does not - is there plans for these notifications to be added in the near future.
The short answer: yes.
The longer answer: the more convoluted portions are not entirely windows specific.
The bit that handles the mangled names can be found here:
https://github.com/facebook/watchman/blob/master/root.c#L748
The bit that handles deletes is in two parts; the first handles things when we're checking exactly the file that we were notified about:
https://github.com/facebook/watchman/blob/master/root.c#L853
The second is a kind of "garbage collection" approach where we're looking at the containing directory and discover that the file has gone away:
https://github.com/facebook/watchman/blob/master/root.c#L1353

Groovy debugger out of sync

I am having a difficulty while attempting to debug some code in grails. It is difficult to put into text, so I have posted a screencast showing exactly what the problem is here. In short, while I am debugging the debugger starts jumping from place to place and not following the program logic I have in place. The only other similar question I have found is a year old, had no solution, and can be found here.
The best guess I have so far is that the debugger is displaying the text I have typed in, but is actually executing an older version of the class file which it has cached somewhere. Therefore, I tried:
cleaning the project
manually deleting all of the class files from the target folder and from the target-eclipse folder
Searching my entire hdd for additional files with similar names
removing my project from the workspace and re-adding it
closing and reopening the IDE
grails refresh-dependencies
Importing the project into a new IDE (I was using GGTS, I switched to IntelliJ)
None of those solutions had any effect. I realized that the issue was in a .groovy file, and I was writing almost pure Java, so I deleted the .groovy file, and re-created the class in a .java file. That solved my problem. Unfortunately I am having the problem again, and this time it is in a controller that heavily relies on the grails framework, so that solution is not an option. Other than also being in a .groovy file, another similarity is that the code breaks on an if statement.
My next steps:
Verify that the application is not executing the code I see by using print functions to monitor actual execution flow.
comment out the entire function and re-add functionality one line at a time to see if I can see what breaks it.
Delete the .groovy file, and re-create it as another .groovy file.
Any help is appreciated, and since I can't find any answers online I will continue to update this question as I learn more.
See my comment on the jira issue that you raised. You have found a problem with the groovy compiler and how it calculates line numbers. This is not a problem with executing the wrong class files or using a broken debugger. The debugger is doing exactly what it is expected to do. It is the compiler that is providing erroneous line number information.
The next step, as described in the issue, is to provide a simple project that recreates the bug. I tried to do so myself, but could not. So, please supply something that we can work with. Then we can notify the groovy compiler team.

Entity Framework 4.1 Code First Changes in Relationships often do not take

I often get errors when running test cases after changing relationships. When checking the relationships on the data diagram I notice that they are often not reflecting any of the changes I did or only some of them, confusing the model. This only seems to be the case when creating the diagram within Server Explorer of Visual Studio. When creating the diagram in SQL Server the changes show up fine.
Unfortunately, this also affects testing the code, because I'm never sure if a fails because of a problem with a change in the relationships I did or Visual Studio not updating. Having to detach and attach the database each time is a bit of a pain.
The database is dropped and recreated correctly, but Visual Studio seems to run the code against a cached version. Had anybody else similar problems, any fix?
I've certainly seen issues where I've updated SPs/function imports and tried to update the associated complex type, the dialog window says 'update', 'delete' etc next to the columns changed, so it's certainly seeing the different, but when applying the update these often don't seem to take and I end up manually adjusting the complex type.
In the above example I'm not sure whether the correct approach is to delete and recreate the type, but the existence of the update functions seem to suggest that an update should be possible. As you say mine too feels like a caching issue and whilst I've not yet found a solution I will be interested to see if you can find a solution, if I make any ground on this I will post back here too!

How to properly delete and re-add Entity Data Model

newbie to Entity Framework here. Using VS 2010 and SQL Server 2008 express DB.
I was having trouble refreshing an Entity Data Model after adding new tables. So, I followed a suggestion I found here to just delete and regenerate the model.
I get to the "Choose Your Data Connection" section of the Entity Data Model Wizard and "Save entity connection settings in Web.config as:" is checked. However, my existing name has a 1 appended to it. For example MyDatabaseEntities is now MyDatabaseEntities1. Of course, I don't want the "1" appended. I killed the existing connection string in Web.config and removed all references to that name in my solution. Yet when I try to continue I'm presented with the following error:
"'MyDatabaseEntites' conflicts with an existing property name in the Application Settings. Please choose a different name"
I can't find a reference to that name anywhere in the solution. I can uncheck that option and it will continue, but it STILL won't add two of the tables in the database. Next, I completely shut everything down, rebooted, and tried again. This time I didn't get the error above, but two of my three new tables still do not get added to the edmx model.
Any ideas are appreciated. Also this seems like it's still pretty buggy even in VS2010/.NET 4. Help restore my faith...I feel like abandoning Entity Framework at this point. Based on my experience so far and some of the other issues posted here, I feel like I'm going to spend more time chasing Entity Framework strangeness than writing useful code.
UPDATE: I found a resolution. The designer doesn't display errors. You have have to look in the native XML (edmx file) to see the errors. See here: ADO.NET Entity Framework: Update Wizard will not add tables
The error is caused by leftover connection strings in settings in "App.Config" file (see solution explorer) and it's in this section:
"connectionStrings" (surrounded by angle brackets)
Just delete it from there.
Restart IIS if you develop web app.
Restart Visual Studio After Deleting The EntityDataModel Connection
String Line from web.config or app.config
Add New Entity Data Model and rename it like old name,
I don't know the specific answer to your problem, but I think I can recommend an approach that will clear up this conflict.
I generally break my EF work into a separate library. If I'm working on Cyberdyne.Terminator, I make an EF class library called Cyberdyne.Terminator.Data. That way, if you want to blow away the model and start over, everything is separate from your dependent files, and in particular, your web.config.
None of this is likely to fix the missing tables, probably. The one thing I've seen where this happens is if I add a table, and then delete it. It will not appear again in the "Add Tables" dialog (and you have to rename it to get it to show). But I thought that was fixed in EF 4.0. Dunno. If the problem persists you might try renaming the table, re-adding it, and then renaming it back if it shows up.
EF is a pain in the ass to be sure. The only thing I can tell you is that I've generally had to work through these headaches, learn the issue, and never be bothered by them again. If you can't stand EF, you might also look at NHibernate - I have a very strong impression of that as well.
Double check your connection strings, and keep scrolling to the right. Most often, when this happens to me, Visual Studio has appended a connection string behind another. I've done this a couple times, and wondered where my app config was (no, there is no app config, just web config in mvc), so the dialog is a little confusing. Sure enough, most likely that connection string is lurking directly behind another!
Just press
Ctrl+F
keys and in dropdown list select 'EntireSolution/CurrentProject', then press enter. where ever this name generated it will show you.
I get into web.config file. so delete that generated complete connection line from there. and re add it again. Then hope you may not get this message again.Thank you..
Actually this is frustrating, since you trying to see in app.config that if there's a another string and you see only 1 string, Actually What VS does is sometimes append second string in the same line. see this picture below
Does it look like there are 2 ConnectionStrings? (ACTUALLY YES)
Now, see this pic:
Also you can press Ctrl+ED to format the config file and see if there's another second string hiding somewhere. Hope this will help someone.
im so sorry for my english
but the solution is simply.
you have to delete the ado.net
then, go to app.conf and delete the connection string<>,
DEBUG your project and finally add the new database through ado.net
TO ADD ADO.NET
RIGHT CLICK ON YOUR PROJECT NAME, THEN, ADD NEW ITEM, DATA AND SEARCH ADO.NET...
I hope help you, have good day!
angelsantacruzm