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.

4
  • What is the purpose of all this abstraction? Commented Aug 7, 2017 at 0:18
  • @RobertHarvey I use this models to my WebAPI layer, in my html templates, as mapped model in my LINQ queries. Commented Aug 7, 2017 at 4:15
  • OK. What is the purpose of that? Commented Aug 8, 2017 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. Commented Aug 9, 2017 at 4:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.