MVC - Abstracting a conversion from an entity (or model) to a ViewModel

535 Views Asked by At

my target is to abstract as much as possible, so i thought something generic for converting from a model (entity) to a viewmodel.

I'd like something like this:

IEntityToModelMapper mapper;
mapper.Convert<MyModel>().Map<MyViewModel>();

or even:

 GenericViewModel model = _mapper.Convert<MyModel>();

When "GenericViewModel" is a base class of all ViewModel, but in this case i'd have problem with casting objects. Maybe an Interface?

Mine are just attempts. How would you implement this?

Thanks

0

There are 0 best solutions below