Reputation: 622
I am creating a Web API application using EF with a code-first approach in Visual Studio 2017. I tried to use enable-migration
, initially I was not working so I installed these packages.
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.2.3
Install-Package Microsoft.EntityFrameworkCore.SqlServer
After installing those packages, enable-migration
worked for me, but when I tried to add a migration using Add-Migration FirstMigration
command, it throws an error
No DbContext was found in assembly 'UserRegistration'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
Please help me how to resolve this issue in Visual Studio 2017.
PS : I have also defined the DBbConnection
in my web.config
file:
<connectionString>
<add name="DefaultConnection"
connectionString="Data Source=(local);Initial Catalog=WebAPIDB;Integrated Security=True"
providerName="System.Data.SqlClient"></add>
</connectionString>
Upvotes: 0
Views: 823
Reputation: 1
public DbSet<ModelClassName> NameForModel {get; set;}
Please include the code above in your model class that has properties you want to migrate in the database please refer to this link How to apply Entity Framework code first approach to a project to make it easier for you to understand.
Upvotes: 0