Best practises for a Web Api

时间:2015-06-26 09:32:36

标签: asp.net-mvc rest asp.net-web-api asp.net-web-api2

I have a Movies table with some basic information and a Reviews table with revies about the movies.

In my app I want to show a list with the name and the avg score of the movie. What is the best practise?

Do I store an avg field in the Movies table and use the API/Movies?

Do I have my API return Movies including the reviews reviews and calculating that in my app (I guess not).

Or Do all the necessary calcs on the server and return the View Model needed?

1 个答案:

答案 0 :(得分:3)

Have the calcs done on the server/database. Assuming you have a back-end db store like SQL server, write a query, stored procedure, or view that does the calc for you on demand. You don't need to calculate this on the client (this would be slow and cause you to need to transfer too much data) and you don't need to store that average anywhere.