0

I have big asp.net web-forms project, I'm using Linq2SQL, I have 1 model per table (same properties as generated classes by Linq2SQL, I add this models to have more controls of fields).

For some tables I need multiple ViewModels, for example for Product table I have following models:

  • ProductBaseViewModel contains Id, Title, Price
  • ProductPageViewModel derived from ProductBaseViewModel and have Description and Review properties
  • ProductBoxViewModel contains Id, StockCount, Title, Url and FormattedPrice
  • ProductWebApiViewModel I use this one in API layer
  • I have 3 more ViewModels that related to Product!

I think having this kind of models are silly and I'm looking for some better solution, is there better way (I'm sure the answer is yes) for handling ViewModels in large projects?

Thanks in advance.

  • What is the purpose of all this abstraction? – Robert Harvey Aug 7 '17 at 0:18
  • @RobertHarvey I use this models to my WebAPI layer, in my html templates, as mapped model in my LINQ queries. – Mehdi Dehghani Aug 7 '17 at 4:15
  • OK. What is the purpose of that? – Robert Harvey Aug 8 '17 at 17:56
  • The main reason is strongly typed models. also I use multiple models, because of performance (specially when I use that model as mapped model in my queries). for ex. I don't need to select Description field every time I select a product it's NVARCHAR(MAX) so I need one model without that. I hope I could mention the point. – Mehdi Dehghani Aug 9 '17 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.