-1

After setting up my initial model class, I right-clicked on the Controllers folder and added an MVC Controller with views, using Entity Framework.

I realized that a lot of code got generated; e.g. the provided properties of my model class are used in the auto-generated code:

public async Task<IActionResult> Create([Bind("Birthday,ID,Username,EmailAddress")] PersonModel personModel )

as well as all the cshtml scripts for the newly-generated view; for instance Index, Create, Edit, Delete, Details, etc... which will define my database columns.

Does this mean if I change the code in the model class, I have to re-create the controller, or do I need to search for and effect the changes accordingly one by one, or is there a better way of doing this?

4
  • 2
    You can either regenerate controllers every time or manually update them. Not really a better workflow there if you want to keep using autogenerated code. Commented Aug 17, 2021 at 6:43
  • 1
    @faso Thank you. Can you please tell me how to re-generate them? Is there an update menu option somewhere to update or re-generate all this code? Commented Aug 17, 2021 at 7:05
  • 2
    Just do all the same steps as when you were generating it for the first time, it should ask you if you want to replace the old code with new code. Commented Aug 17, 2021 at 7:09
  • 2
    @faso Your two comments answered my question. If you would put them together in the from of a brief answer, I will mark it as the accepted answer! Thanks Commented Aug 17, 2021 at 11:54

1 Answer 1

1

You can either regenerate controllers every time or manually update them. Not really a better workflow there if you want to keep using autogenerated code.

Just do all the same steps as when you were generating it for the first time, it should ask you if you want to replace the old code with new code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.