Unable to add Migration to Entity Framework 7 - entity-framework

I downloaded a sample Asp.net 5, Mvc 6, EF 7 project from internet. It is working fine, but when I try to add Migrations using console it says
Please run "Dnu restore" to generate a new lock file.
I ran this inside the src/projectName folder on console, If I try to run
dnx ef command its still says the same error.
How can I resolve this error ?

Related

I deleted Migrations file and folder .I try again dotnet ef migration add initial but I see Built failed

I am working on an ASP.NET Core MVC app. I deleted the Migrations file and folder. I try again using .NET EF Core migration and adding initial, but I see the build failed. How can I do this?
Your question does not explain many things like did you created any other class or namespace in migrations folder and accidentally deleted it as well.
Build failed error is caused by some missing file, reference or some syntax error.
Check you Error List tab in visual studio.
I use to write my command ">dotnet ef migrations add initial" in CLI and I could see only "Build Failed" . Then I used Package Maneger Console "PM> add-migration initial" and take more description. when I fixed errors I am succed successful
[Link]https://www.entityframeworktutorial.net/efcore/entity-framework-core-console-application.aspx

Update-Database is obsolete - Visual Studio 2015 Update 3

I've done the upgrade for Visual Studio 2015 Update 3, One project is using ASP.Net Core but only for front end JS and CSS using gulp etc. I've just tried to run migrations on the project with migrations and get the following:
Update-Database is obsolete. Use Apply-Migration instead.
Using project 'ProjectName'
Build started...
Build succeeded.
Using start-up project 'MyProject'.
Using application base 'pathlocation'.
Using application configuration 'pathlocation'\Web.config'
Using data directory ''pathlocation'\App_Data'
Using assembly 'My.dll'.
Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load file or assembly 'EntityFramework.Commands' or one of its dependencies. The system cannot find the file specified."
I can't see that I've upgraded to EF 7, and I've uninstalled and reinstalled EF 6 in the project. Any suggestions as to what I'm missing?
I'm sure this was something to do with .Net Core messing up the tooling. To resolve I ran VS as admin. Removed all the EF 7 references in the packages.config in the .Net Core project. Then uninstalled and reinstalled EF 6 through Package Manager Console:
Uninstall-Package EntityFramework -Force
Install-Package EntityFramework -Pre
Using EntityFramework 7? Did you set your dnvm?
first you have to run from the cmd of your project folder this command:
dnvm upgrade
Then try again to use migration, but only from the cmd, and using the dnx command.
Example:
"dnx ef migrations add Initial"
more info: here

Add-Migration throws error with no configuration found

When I try to create a new migration using EF Code-First the package manager console gives me an error saying: 'No migrations configuration type was found in the assembly 'Project.DataAccess'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).'
I've previously used this method on THIS project successfully and the project do have a Configuration file with all the correct inheritance.
I also tried specifying all the parameters -Name, -StartupProjectName etc. but no change. When trying to re-enable migrations VS is not successful creating the Configuration with inheritance from my context-class.
Any suggestion on this issues? Using EF 4.3.1 and Code-First
This problem was resolved by installing EF 4.3.1 using the Package Manager Console. I had done a manual upgrade and for some reason that didn't do the trick.

How to use Entity Framework code-first

I created some classes, and configured the connection string.
But still got an error:
Unhandled Exception: System.NotSupportedException: Model compatibility cannot be
checked because the database does not contain model metadata. Model compatibility
can only be checked for databases created using Code First or Code First Migrations.
Check the EF version you have, latest is 4.3.1.
You also need to configure a DbContext class. check this: http://msdn.microsoft.com/en-us/data/gg685467
i fixed it
by Run the ‘Enable-Migrations’ command in Package Manager Console.
Here is what worked for me if you are fine with deleting and recreating the database from scratch.
First, run the following commands from package manager console.
sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
Next, delete the mdf and ldf files from the app_data folder of your project.
Here comes the critical part. Usually you will run update-database. If you do that the exception will still be thrown.
DO NOT Run update-database. INSTEAD directly run your project code. The EF will recreate the database.
These steps worked for me. Let me know if this helps you.

LINQPad 4 unable to find EntityFramework

I'm trying to use LINQPad 4 (the latest beta) with Entity Framework POCO classes. I take the normal path of creating a new connection and then selecting "Entity Framework DbContext POCO(4.1) and then selecting my he assembly holding my classes. When I do so I get the following message
"Could not load file or assembly EntityFramework. Version=4.1.O.O,
Culture= neutral, PublicKeyToken=b77a5c561934e089 or one of its dependencies.
The system cannot find the file specified."
I'm able to load the assembly from my application just fine. What gives? It seems a bit different from the previous problem like this reported in the CTP.
I had the same problem today, this is how I solved it:
Apparently the LINQPad 4.36.3 requires in some way Entity Framework 4.2 :/
It was released last week: ADO.NET blog
What I did is:
Installed EF4.2 via NuGet
Rebuilt the project
Copied all my project .dll files to LINQPad folder (including the 4.2 EF.dll)
I read here that I need to add something to the LINQPad.exe.config file but it was already there..
[At this point I tried removing that assembly redirect and ran it against my 4.1 dll, did not work, was still looking for 4.2]
Closed VS and uninstalled EF4.1
Thats it, after that both my project is now running on 4.2 and LINQPad works as well.