我有一个类FOOS:是否可以将对象映射到Automapper中的List?
public class Foos
{
public string TypeName;
public IEnumerable<int> IDs;
}
是否有可能将其与AutoMapper映射到富的对象的IList?
public class Foo
{
public string TypeName;
public int ID;
}
我有一个类FOOS:是否可以将对象映射到Automapper中的List?
public class Foos
{
public string TypeName;
public IEnumerable<int> IDs;
}
是否有可能将其与AutoMapper映射到富的对象的IList?
public class Foo
{
public string TypeName;
public int ID;
}
Omu的回答让我想到了一个想法如何解决问题(建议为+1)。我用ConstructUsing()方法和它的工作对我来说:
private class MyProfile : Profile
{
protected override void Configure()
{
CreateMap<Foos, Foo>()
.ForMember(dest => dest.ID, opt => opt.Ignore());
CreateMap<Foos, IList<Foo>>()
.ConstructUsing(x => x.IDs.Select(y => CreateFoo(x, y)).ToList());
}
private Foo CreateFoo(Foos foos, int id)
{
var foo = Mapper.Map<Foos, Foo>(foos);
foo.ID = id;
return foo;
}
}
:)它很可能与http://valueinjecter.codeplex.com/,这其实事情之一,我使用它为 – Omu 2010-08-02 22:24:20
@Omu我从来没有见过这个项目......谢谢! – stacker 2010-08-03 04:55:13