ASP.NET MVC - database first

Author
Discussion

anxious_ant

Original Poster:

2,626 posts

85 months

Friday 2nd December 2022
quotequote all
Taken a crash course in ASP.NET MVC to support a project.
I am struggling around inserting new record on a table with one-to-many relationship and wondering if someone here can help with some code snippets.

The main table is User with one-to many with UserRoles (FK User.Id)

Based on database first approach how do I build the model and controller which allows inserting new User and UserRoles records?

Mr Happy

5,707 posts

226 months

Friday 2nd December 2022
quotequote all
Use EntityFramework to build the model, and use the context created by EF to do your CRUD calls.

No point in re-inventing the wheel for something like that.

This MS Learn link handles pretty much your complete scenario: https://learn.microsoft.com/en-us/ef/ef6/modeling/...