Skip to main content

Posts

Showing posts from July, 2017

Efficient custom mapping from data model to ViewModel/Dto or vice versa with LINQ support

How many lines of codes we waste on mapping from one source to a destination like DataModel to ViewModel.  There are well-known Mappers available to do the same but nothing can come close in terms of performance by using manual mapping just that we need to write at too many places or takes a huge chunk of code lines in our main codes, may be under controllers, services or where ever you prefer projection in code. The idea is to develop a proper way to deal with mappings. Some time back I had written code for manual mapping under LINQ queries.  Manual model mapping - LINQ projection technique , this still works great. The idea is to create a cleaner solution as a whole new package for handling Mapping which can support general mappings between models and support of LINQ projection to select the limited number of rows as required. Primary objectives of the implementation. - A Data model to view model/DTO/or any other. - view model/DTO/or any other to a data model. - Support of LI