问题
I am a newby in the beautiful world of Microsoft Azure and made my first hello world website. The next step is to create a database (entityframework) but I get an exception while creating the database from PackageManagerConsole (PMC). I read a few posts on the web that explained that I need to add the startupprojectname to the PS command, but unfortunatelly that doesn't resolve my problem.
I have 2 projects in my solution.
- "partyonwebsite" which is the startup project and obviously my website :).
- "models" where I will design my models / entities.
In the "models" project I have the classes "User" and "UsersDb". UsersDb is the class that inherits from DbContext.
Now, when I execute the following line in PMC:
enable-migrations -StartUpProjectName "PartyOnWebsite" -ContextTypeName "Models.Users.UsersDb"
I receive the following (not very helpful) error:
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
I've had a look at get-help enable-migrations and played around a bit but not a lot of luck.
Did anybody bump into the same problem? Or can you point me in the right direction to help me solve it?
Thanks a lot in advance!
Bas
回答1:
Solved. If you run into the same problem, make sure that EntityFramework is setup correctly for your seperate "Models" project.
- Open "Manage NuGet packages for solution" in solution explorer (right click solution in solution explorer)
- Select "Installed packages"
- Select "EntityFramework" and click "Manage"
- Check your "Models" project (I checked both my website project and the "models" project)
Run your enable-migrations command again.
I also added a project reference from my Website project to the Models project, I don't know if that matters.
The command that successfully executed after my adjustments in NuGet:
enable-migrations -ProjectName Models -ContextTypeName Models.Users.UsersDb
Hope this answer helps another lost soldier in his path to get his first app running in Azure :).
Cheers,
Bas
来源:https://stackoverflow.com/questions/14007169/entityframework-enable-migrations-argumentexception