Does AutoMapper's convention based mappings wo

2019-08-02 02:43发布

问题:

I apologize if this is a duplicate but I did not find anything that seemed to be matching up with what I am looking for.

As we all know in Automapper we can perform convention based mappings...

My Question

Is it possible to access extension methods (LINQ.First()) on objects in a collection, to go "n" levels deep? See example below

My Entities

public class Store
{
    public IList< Departments > Departments {get;set;}
}

public class Departments
{
    public bool Open {get;set;}
}

What I want to be able to do

Mapper.Map< Store, StoreEditModel >();

public class StoreEditModel
{
    public bool DepartmentsFirstOpen {get;set;}
}

Applicable Use (So you don't think I'm stupid)

The applicable use is to assume that all items in the collection should be in the same (Open)state.

So when my edit model comes back to be processed, I can open or close all Departments in the Store respectively.

Outside Resources I already read the following on AutoMapper's site.... http://automapper.codeplex.com/wikipage?title=Flattening

回答1:

Looks like with the new release AutoMapper now supports this.

Source: http://automapper.org/blog/2011/09/22/automapper-20-released/