Are Timers and Loops in .Net Accurate

Enable-Migrations Exception calling SetData with 2 argument(s)

Other answers suggest this is an issue with your startup project.

As your project is a library, you could try setting your unit test project as your startup project per this answer.

You could also try setting the default project in Package Manager Console to your library project per the accepted answer here.

You might run into issues with where the migrations are created. If you need further control, in EF6 there are various arguments you can use with Enable-Migrations as detailed in this answer but I don't have enough knowledge in this area to guide you further. You might need to do some reading.

Entity Framework cannot create any migrations

As @Ivan Stoev pointed out, I was using the wrong EF version. Here is a short article explaining the difference between EF and EF Core.

Can't run EF migration where DbContext connection string is set at runtime and separate project from application

Okay, so after much looking, you can't do this by default. No tooling for class libraries since January at all, which seems horrible to me. And no tooling as the link I posted mentions for a .NET CORE class library targeted at 461 using EF6, because EF6 tools do not recognize project.json dependency format.

However, blessed be, a gentleman by the name of Mohammad Rahhal created such a library to accomplish this: https://github.com/mrahhal/Migrator.EF6/blob/master/README.md

And using the information described in this issue: https://github.com/mrahhal/Migrator.EF6/issues/9

I was able to successfully run a migration, it does require some hacky stuff, but it works for the time being, better than other alternatives provided elsewhere.

1) Download this nuget package for Migrator.EF6.Tools nuget.

2) Change project.json to include:

{
"version": "1.0.0-*",

"dependencies": {
"EntityFramework": "6.1.3",
"Migrator.EF6.Tools": "1.0.5"
},

"frameworks": {
"net461": {}
},

"buildOptions": {
"emitEntryPoint": true
},

"tools": {
"Migrator.EF6.Tools": {
"imports": "portable-net45+win8+dnxcore50",
"version": "1.0.5"
}
}
}

3) Add a program.cs file with Main stub to the class library project:

public class Program
{
public static void Main(string[] args)
{
}
}

You are now set to run migrations from VS2015 Dev Command Prompt. Navigate to the project directory, and run the migration commands described in the readme linked above.

However, it should be noted, once you are done running migrations, set emitEntryPoint value to false again so it can still be treated like a normal class library. Basically you are tricking the EF tooling to think your class library is a console app, but you don't want it to be treated like that for deployment.

Enable-Migrations installation error

Found the problem!

The issue was that the startup project in my solution was a modeling project.
For some reason when enabling migrations on my project, the module looks at libraries related to the startup project.

Changed my startup project to be a test project in the solution and everything worked.

UPDATE

Make sure your startup project contains the app.config or web.config file you want to use to connect to database. This is the file that it will be used to generate migrations even if your DbContext is located on a different project. You can set the project containing your DbContext as the startup project.



Related Topics



Leave a reply



Submit