Scaffolding in .NET Core (generate API controllers – CRUD (or MVC controller with views in necessary)

Right click on ‘Controllers’ folder –> Add –> New Scaffolded Item…

For api controller without views select ‘API Controller with actions, using Entity Framework’ and click ‘Add’.
If MVC then choose ‘MVC Controller with views, using using Entity Framework’

On next view select your model (you need create model before generate code) and select data context (if you don’t have already existing one then you can create clicking ‘+’ sign)

Click ‘Add’ and it should start generate code (controller with CRUD to your model).

In older project you can get error trying to generate code, could be problem with e.g. unupdated packages: Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Design’.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: