简体   繁体   English

AutoMapper:将树转换为实体列表

[英]AutoMapper: Converting a tree to an entity list

I have "Source" classes and "Destination" class: 我有“源”类和“目标”类:

public class ActionSource
{
    public string Action { get; set; }
    public IEnumerable<PlaceSource> Places { get; set; }
}

public class PlaceSource
{
    public string Place { get; set; }
    public IEnumerable<EventSource> Events { get; set; }
}

public class EventSource
{
    public string Event { get; set; }
}

public class EventInfoDestination
{
    public string Action { get; set; }
    public string Place { get; set; }
    public string Event { get; set; }
}

How can a map ActionSource data to IEnumerable<EventInfoDestination> with AutoMapper? 如何使用AutoMapper将ActionSource数据映射到IEnumerable<EventInfoDestination>

There isn't much auto about this mapping. 这种映射没有太多的自动性。 You should do it by hand. 你应该手工做。 AM would only get in the way. AM只会妨碍您。

    from place in source.Places
    from ev in place.Events
    select new EventInfoDestination { Action = source.Action, Place = place.Place, Event = ev.Event};

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

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