Context: ASP.NET MVC 2.0, C#
At the moment I use following pattern:
using (var db = new MyDatabaseDataContext()) {
var model = new MyPageModel();
model.player = db.blah.blah.blah;
model.info = db.blah.blah.blah;
model.bossKillCount = db.blah.blah.blah;
}
It works fine, one problem is that I have to redefine those models for each page, since models are slightly different.
QUESTION: Would it be OK to wrap db instance into MyPageModel class and keep data context open?
I feel that some sort of dynamic data structures would be perfect here, so I could use mix-ins to offload the model differences. I tried using inheritance but with single inheritance it didn't get much better.