Entity framework 7, visual studio 2015, console commands don't work

asp.net-core-mvc c# entity-framework-core visual-studio-2015


I am using the ASP.NET 5 Web application Template (which is using EF7 and MVC 6), the one with the individual User Accounts, and I have the following problem:

When I add my own DBSet to the ApplicationDbContext class, and then going to a page which is trying to use this new DBSet, it doesn't work, I get this:

A database operation failed while processing the request.
SqlException: Invalid object name 'WallMessageModel'. 

There are pending model changes for ApplicationDbContext
Scaffold a new migration for these changes and apply them to the database from the command line:

 dnx . ef migration add [migration name] 
 dnx . ef migration apply

Now when I run these commands, or any "dnx" commands I get:

CategoryInfo          NotSpecified: Error: Unable t...stemindsWebsite:String, RemoteException    FullyQualifiedErrorId : NativeCommandError

And if im trying to run any "k" commands im getting:

CategoryInfo          : ObjectNotFound: k:String, CommandNotFoundException    FullyQualifiedErrorId : CommandNotFoundException

I'm using "EntityFramework.SqlServer": "7.0.0-beta5", "EntityFramework.Commands": "7.0.0-beta5"

I tried using the 7.0.0-* version and it still doesn't work for me. Can you please tell me what am I doing wrong?

Basically, I believe that EF commands are not installed properly on my machine (via Visual Studio 2015/PowerShell). However, there doesn't seem to be any reference that shows how to get those installed (shouldn't they be built into VS2015 when using EF7?).

12/2/2015 12:34:18 PM

Accepted Answer

When you add another DbSet to your ApplicationDbContext class or add/modify any other existing entity class, your runtime model changes from database model. Hence you need to scaffold a new migration and apply it to database so that both models are in sync with each other. As the exception message suggests, you should run those commands to do that.

For those commands (or any other dnx commands) not running, dnx commands are not built in VS2015. They come from Microsoft ASP.NET and Web Tools extension for visual studio. Please verify that you have it installed for your VS. That will enable you to run dnx commands. k is very old term and it was renamed to dnx. Also beta5 is old version, the latest version is RC1, which has many more features. Detailed information on how to install and use Web Tools is available at https://get.asp.net/

12/3/2015 12:56:56 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow