简体   繁体   English

AutoMapper基于约定的映射是否可以与LINQ扩展方法一起使用?

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

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... 众所周知,在Automapper中,我们可以执行基于约定的映射...

My Question 我的问题

Is it possible to access extension methods (LINQ.First()) on objects in a collection, to go "n" levels deep? 是否可以访问集合中对象的扩展方法(LINQ.First()),从而深入“ n”级? 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 外部资源我已经在AutoMapper的网站上阅读了以下内容。... http: //automapper.codeplex.com/wikipage ? title=Flattening

Looks like with the new release AutoMapper now supports this. 在新版本中,AutoMapper现在支持此功能。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM