Self model projection does not take into account Ignore
option for inner collections
#3588
Answered
by
lbargaoanu
rgilmutdinov
asked this question in
Q&A
-
Source/destination typespublic class ClassA
{
public string Name { get; set; }
public string Type { get; set; }
}
public class ClassB
{
public string Name { get; set; }
public List<ClassA> Classes { get; set; }
} Mapping configurationvar configuration = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ClassA, ClassA>()
.ForMember(dest => dest.Name, opts => opts.MapFrom(src => src.Name))
.ForAllOtherMembers(opts => opts.Ignore());
cfg.CreateMap<ClassB, ClassB>()
.ForMember(dest => dest.Name, opts => opts.MapFrom(src => src.Name))
.ForMember(dest => dest.Classes, opts => opts.MapFrom(src => src.Classes))
.ForAllOtherMembers(opts => opts.Ignore());
}); Version: 10.1.1Expected behaviorI expect that Actual behavior
Steps to reproduceList<ClassB> source = new List<ClassB>();
source.Add(new ClassB() { Name = "b1", Classes = new List<ClassA>() { new ClassA() { Name = "a1", Type = "type" }, new ClassA() { Name = "a2", Type = "type" }, new ClassA() { Name = "a3", Type = "type" } } });
var mapper = configuration.CreateMapper();
var result = source.AsQueryable().ProjectTo<ClassB>(mapper.ConfigurationProvider);
ClassB target = result.First();
foreach (ClassA classA in target.Classes)
{
if (!string.IsNullOrEmpty(classA.Type))
{
// we shouldn't get here
Console.WriteLine(classA.Name + " " + classA.Type);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
lbargaoanu
Feb 26, 2021
Replies: 1 comment
-
That's not supported. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lbargaoanu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's not supported.