0

我在显示某些全天活动的小时数和出勤率表时遇到问题。此活动允许为一天中的每个小时注册与会者。我想知道显示当天每小时的与会者人数的最佳方法是什么?问题在于没有与会者登录的时间。显示这个“空”行(零值的小时)的最佳方法是什么?我找到了解决方案,我可以在一些存储过程中处理这个问题,这些存储过程将映射到一些仅用于显示的实体,但我不太喜欢这种方式。解决这个问题的最佳方法是什么?我正在使用带有实体框架的 ASP.MVC 3。

4

1 回答 1

0

Your problem stems from the fact that you treat your database schema as view model.

You should introduce model classes that will correspond to what the view is displaying. You will be than able to create in controller 'empty' instances of those models, with hours set to 0. Those model will be than translated to EF entities in your controller and persisted.

By effectively binding your database schema to views you've limited your options. MVC is all about decoupling of views and data persistence.

Yes, in simple scenarios you can get away with passing your EF entities to views, but in more complex ones (like the one you've encountered) decoupling is necessary.

于 2012-06-25T22:07:45.620 回答