3
votes

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

2

2 Answers

4
votes

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

0
votes
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