Does AutoMapper's convention based mappings work with LINQ extension methods?

守給你的承諾、 提交于 2019-12-24 11:29:32

问题


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/



来源:https://stackoverflow.com/questions/7125955/does-automappers-convention-based-mappings-work-with-linq-extension-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!