I have created one new Migration in Visual Studio for my solution and then removed it (just remove files from Visual Studio). But now, when I try to do Update-Database it tries to apply that removed migration. I checked the whole solution and never seen any notification about that removed migration, it's really removed from solution. But package manager try to apply it. Why, where is it stored and how to remove at all?
Related
I've been trying to set up EFCore with .NET6. When all my Models/Entities are inside a folder, the Initial Migration I ran removes all the dependencies(some) from the project and results in a failed build. But when I initially store my model in the root directory and run the same command it works.
This is the folder structure which causes the issue
Update
The last time I tried migrations worked if I placed the models and entities at the project's root, but now, even if I do, the same error happens. Please help me with this error. Thanks in advance.
Apparently, Visual Studio did not save the changes to the .csproj file on disk when I installed all the NuGet packages which resulted in the build failed error. This issue will not happen when we use visual studio to build the project because it will persist the changes to the disk when we do that but I used the CLI to build and run the migrations which resulted in this error.
I have two different projects that use Entity Framework, to generate my migrations I use the commands Add-Migration name and Update-Database.
Now, for some reason, the first project always makes sure that my project is built with the latest code by issuing a build after every one of these commands that I do inside Pacakge Manager Console.
This is what I see as the correct way.
But my second project, despite being very similar, it never do that build automatically as the first one does.
So If I need to generate a new migration, I first run a build, then run Add-Migration name, then build again, then run Update-Database.
Is there a option somewhere that I'm not aware that enables or disables that behavior?
Ps. my visual studio version is 2017 Enterprise
Thanks
First I would love to comment instead giving an answer but I can't yet.
In your startup file in the first project do you have something similar to this?
dbContext.Database.EnsureCreated();
Or
dbContext.Database.Migrate();
If the answer is yes that's maybe why in one of your projects when you start it the project update the database.
I've been working on a project with a coworker and we're using Visual Studio 2017 as IDE and also Git to push the versions to VS repository. We had a few problems and decided to start a new project in Visual Studio with the content we already had.
The weird thing is: when cloned the repository to my computer and synched, some of the references were lost. A yellow triangle appears next to the lost references icons in Solution Explorer, and it doesn't have a path set like the ones that work. Also, inside Source > Repos, the project folder has all files, including the ones that are missing. I tried deleting the project and cloning it again, tried to download only the .zip file and starting the project offline, and also running VS 2017 as administrator (it appears this solved similar problems for others before) and nothing worked. My coworker (who pushed the project to the repo in first place) can compile normally and is not facing this reference problem.
Has anyone ever experienced this issue?
We're using VSTS with a git repository, and this happens all the time, especially when pulling updated solutions. I find a clean and rebuild fixes the problem.
You can run in the Package Manager Console the following command to clean up the nugget packages:
Update-Package -reinstall -ProjectName XYZProjectName
or run it for the whole solution:
Update-Package -reinstall
In my case after a merge with the master branch, I had conflicts in the project file (.csproj). When resolving the issue VS2019 automatically had unloaded the project file where those conflicts were and I didn't notice. A check for that might save time for someone.
I once experienced it when I was having a Visual Studio 2015 project open and then pulling new git commits. The new project I was pulling was was set up for Visual Studio 2017 though.
So my VS 2015 was open and dsiplaying the now VS 2017 project. I believe it only contained one nuget package, however this was not downloaded correctly and instead the package was displayed as a missing file.
Maybe this is happening for you too?
Same problem in VSC 2021 version 1.63.
Solution - Removed project folder from workspace:
CTRL+Shift+P, search for and execute the
"Workspace: Remove Folder from Workspace" command.
Then reopened the project folder and was OK
I have created a new ASP.NET 5 project in latest Visual Studio. When I try to add a reference to either my project, nuget or even edit project.json file I always get an error that says I have to run "dnu restore" manually because of some issues with project.lock.json file that wasn't automatically updated. Dnu restore does indeed help, but it's clearly a bug in Visual Studio. Any way to fix it?
A couple of things to check...
First of all, keep your project.lock.json file out of source control. dnu restore will regenerate it often.
Secondly, double-check your user environment variables. Make sure the following is in your Path:
C:\Users\<YourUserName>\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-final\bin
I have VS2015 Update1 RTM installed, and do not experience this, so I doubt it is a bug. If none of the above helps though, it may be an installation misconfiguration of your VS. Perhaps try it on another machine (or VM) if you can.
If I do any changes to my EF 5.0 model, VS does not seem to see the changes. I have tried adding a new table, which shows up fine in the model, but then if I try to use it somewhere the table does not show up in intellisense and I can't use it.
I have also tried changing datatypes of a column, which again shows up fine if I look at the .edmx model file, but visual studio will still give me compiler errors on that field because I am trying to assign the incorrect datatype.
If I delete the EDMX completely, and recreate it, then the changes work fine. but it is tiresome to regenerate from database each time when I should be able to just "update model from database" and rebuild.
I have never had these problems with EF before. Does anyone know the cause or the fix to this problem?
Thanks.
First Build your Project and if it was successful, right click on the "model.tt" file and choose run custom tool. It will fix it.
Again Build your project and point to "model.context.tt" run custom tool. it will update DbSet lists.
If this is the bug with the edmx file located in a folder it is now fixed - download and install VS 2012 Update 1. You can get it from: http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update
This is apparently a bug in the Entity Framework that the model does not get updated when your Edmx file is located inside a folder.
The workarounds available at the moment are:
Install VS 2012 Update 1 which should fix the bug.
If you are not in a position to install Update 1, you will have to right click on the model.tt T4 template file and click run custom tool. This will update the classes for you.
Hope that helps someone out there.
Link: http://thedatafarm.com/blog/data-access/watch-out-for-vs2012-edmx-code-generation-special-case/
I also had this problem, however, right-clicking on the model.tt file and running "Custom tool" didn't make any difference for me somehow, but a comment on the page Ghlouw linked to mentioned to use the menu item "BUILD > Transform All T4 Templates." which did it for me
Right click the .tt file and select "Run Custom Tool", that should update it:
You should have a <XXX>Model.tt file somewhere which is the T4 template that generates your model classes.
If it is in a different project, it will not update when you save the edmx file.
Anyway, try right-clicking on it in Solution Explorer and choosing Run Custom Tool
I searched for this answer because I had a similar situation in VS2013. In my case, I found that a simple "Clean Solution" cleared out all the old definitions.
Are you working in an N-Tiered project? If so, try rebuilding your Data Layer (or wherever your EDMX file is stored) before using it.
I've also experienced this problem with none of the classes being generated under the model.tt file. In my case it was down to issues with how I had built the DB in SQL2012. I'd set a column in a table to nullable that was also a foreign key and although I think you should be able to do this it caused a problem in EF5.
As soon as this was cleared and the diagram updated from the database they reappeared.
EF5 VS2013
After Changing the laptop When I updating Entity Framework model, stored procedures are not seen in code
What I have done to make this working
Update visual Studio 2012 Update 5 (Not Working)
Update/Modify from Programs (Not working)
After update stored procedures, build the project again then go to context.cs, right click and run custom tool (Not Working)
Doing RND (Someone says the issue is due to some permissions in MSSQL) But unfournately I have done alot of permission in MSSQL but (Not Working)
Install 2019 and run the project. Now everything works fine
Conclusion
Visual studio 2012 have a bug (bug is resolved in Update 1, 2, 3 and 4)
Change the Visual Studio version will resolve the issue
I had this problem in EF 6 using Visual Studio 2022. I tried all of the things here plus cleaning and rebuilding the solution, deleting the stored procedure out of EDMX and the database and re-updating, closing VS, and restarting my computer. None of those things worked. What ended up fixing it was simply opening the DTSEF.vb file. When I did that, Visual studio found the missing properties in the result object.