MVC: How to work with entities with many child entities?

后端 未结 5 2129
温柔的废话
温柔的废话 2020-12-28 22:13

In the current examples on ASP.NET MVC I see quite basic entities, with simple CRUD methods.
But I\'m not sure about what to do with more advanced models. Let me give an

5条回答
  •  时光说笑
    2020-12-28 22:38

    Your design should initially focus on the entities. You have car, employees and inventory. Write a controller for each one of these. That will give you the basic routes:

    • /cars/{action}/{id}
    • /employees/{action}/{id}
    • /inventory/{action}/{id}

    From here you should be able to write a new route with a custom route constraint with the following structure:

    /cars/{id}/part/{id}/
    

    This is also slightly better than /cars/{id}/carpart/{id} because the word car in carpart is redundant. /car/.../part/ indicates that part is for a car.

    Thinking about things like these for URI design is really important early on because changing the URI design later will break search engine indices, bookmarks and links.

提交回复
热议问题