Saurabh
Saurabh

Reputation: 1631

How to Update DBContext Class in Entity Framework Core

I am using Entity Framework Core in my project , Created a DbContext class using the command

PM> Scaffold-DbContext "Server=servername;Database=DBname;User Id=user;Password=password;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context QuestionnaireEntities -Tables Category_Master,Item,Option_Master,Question_Master,Sub_Category_Master,Sub_Item

It is Creating DBContext Class perfectly , But if i want to update my DBContext from database than how i can do it in EFcore , In EF its easy just by doing right click and selecting option update from Database

Additionally how can i use stored procedure in my DBContext class

on msdn website they mentioned a command

PM> get-help scaffold-dbcontext –detailed

But it does not have any info about updating DBContext and adding stored procedure in it

How can i do that in EF Core I am using VS 2017 Community edition with .Net core 2.0 and EFcore 2.0

Upvotes: 8

Views: 13447

Answers (2)

Saeed Ahmad
Saeed Ahmad

Reputation: 73

This is simple query just run this in console here you can mention dbcontext if 
you have multiple dbcontext files.  
Scaffold-DbContext "Server=servername;Database=dbname; 
User ID=userid;Password=password; MultipleActiveResultSets=true;" 
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force -context 
DbContext 

Upvotes: 1

Jaliya Udagedara
Jaliya Udagedara

Reputation: 1196

You can re-scaffold with -f/--force flag and this will overwrite existing files.

Upvotes: 5

Related Questions