开发者

Can AutoMapper select a value T from a child collection into a new list<T>?

开发者 https://www.devze.com 2022-12-25 01:17 出处:网络
I have an object like this: public class Foo { public string Title { get; set; } public IList<Foo开发者_Go百科Child> Children { get; set; }

I have an object like this:

public class Foo {
    public string Title { get; set; }
    public IList<Foo开发者_Go百科Child> Children { get; set; }
}

public class FooChild {
    public string Title { get; set; }
}

I want to map this onto a view model like this:

public class FooDTO {
    public string Title { get; set; }
    public List<string> ChildrenTitles { get; set; }
}

I know I could do this by creating a FooChildDTO and creating a map for it, but I really just want to coalesce the children titles into a simple list of strings.


No, not automatically right now. You can do a resolver or type converter for FooChild -> string, but nothing that looks at the name of the property and auto-rolls it up. This is one of the big enhancements I'm looking at for 2.0, however.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号