Published on

Casting one list to another with Omu.ValueInjecter

Authors
  • avatar
    Name
    Mike Barram
    Twitter

Omu.ValueInjecter is great for quickly casting one entity to another, especially when the property names match up, as there’s no configuration to do.

This is really handy if you have a view model that’s just a cut down version of your model and you want to get the data from the model into the view model.

If you’ve got a list of model entities that you want to cast to a list of view model entitites, you can do so without looping through them:

var MyViewModels = db.MyModel.ToList().Select(p => new MyViewModel().InjectFrom(p)).Cast<MyViewModel>();

Based on this:

http://stackoverflow.com/questions/5443763/valueinjecter-with-iqueryablet