Skip to content

Instantly share code, notes, and snippets.

@cryo75
Created February 28, 2017 15:01
Show Gist options
  • Save cryo75/ea78d9251b9159137a5fd038a83b160b to your computer and use it in GitHub Desktop.
Save cryo75/ea78d9251b9159137a5fd038a83b160b to your computer and use it in GitHub Desktop.
Error on flatting
public class Nested
{
public int Property1 {get;set;}
public string Property2 {get;set;}
}
public class Model
{
public int Id { get; set; }
public int ParentId { get; set; }
public int NestedId { get; set; }
public int Position { get; set; }
public bool? IsOk { get; set; }
public virtual Nested Nested { get; set; }
}
public class Dto
{
public Guid Guid { get; set; }
public Guid ParentGuid { get; set; }
public int Id { get; set; }
public int ParentId { get; set; }
public int NestedId { get; set; }
public int Position { get; set; }
public bool? IsOk { get; set; }
[XmlIgnore]
public int Property1 { get; set; }
[XmlIgnore]
public string Property2 { get; set; }
}
Mapper.Initialize(cfg =>
{
cfg.CreateMap<model, dto>()
.ForMember(dest => dest.Guid, option => option.Ignore())
.ForMember(dest => dest.ParentGuid, option => option.Ignore())
.ForMember(dest => dest.Property1, option => option.MapFrom(src => src.Nested.Property1))
.ForMember(dest => dest.Property2, option => option.MapFrom(src => src.Nested.Property2))
.ReverseMap();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment