I have a Box object which has a list of SerialNumber objects nested within it. I'm trying to map the SerialNumberName property of each SerialNumber in each Box to a model called BoxedElectrodesModel.
Here is my Box class and its nested SerialNumber class:
public partial class Box
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Box()
{
this.SerialNumbers = new HashSet<SerialNumber>();
}
public int BoxID { get; set; }
public System.DateTime DateCreated { get; set; }
public Nullable<System.DateTime> DateShipped { get; set; }
public string TrackingNumber { get; set; }
public Nullable<System.DateTime> DateReceived { get; set; }
public bool Active { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SerialNumber> SerialNumbers { get; set; }
}
public partial class SerialNumber
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public SerialNumber()
{
this.Comments = new HashSet<Comment>();
this.WIPHistories = new HashSet<WIPHistory>();
}
public int SerialNumberID { get; set; }
public int IncomingLotID { get; set; }
public string SerialNumber1 { get; set; }
public string LamPurchaseOrder { get; set; }
public string LamLineNumber { get; set; }
public bool Refurbished { get; set; }
public int WIPLocationID { get; set; }
public int StatusID { get; set; }
public int RouteSectionStepID { get; set; }
public Nullable<int> RejectCategoryID { get; set; }
public Nullable<int> BoxID { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Comment> Comments { get; set; }
public virtual IncomingLot IncomingLot { get; set; }
public virtual RejectCategory RejectCategory { get; set; }
public virtual Status Status { get; set; }
public virtual WIPLocation WIPLocation { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<WIPHistory> WIPHistories { get; set; }
public virtual Box Box { get; set; }
public virtual RouteSectionStep RouteSectionStep { get; set; }
}
...and here is my 'BoxedElectrodesRowModel' class and its nested SerialNumberModel class:
public class BoxedElectrodesRowModel
{
public int BoxId { get; set; }
public List<SerialNumberModel> SerialNumbers { get; set; }
public Nullable<System.DateTime> DateCreated { get; set; }
}
public class SerialNumberModel
{
public string Name { get; set; }
}
Here's my AutoMapper code:
c.CreateMap<Box, BoxedElectrodesRowModel>()
.ForMember(dest => dest.BoxId, opts => opts.MapFrom(src => src.BoxID))
.ForMember(dest => dest.SerialNumbers.Select(sn => sn.Name), opts => opts.MapFrom(src => src.SerialNumbers.Select(t => t.SerialNumberName)))
.ForMember(dest => dest.DateCreated, opts => opts.MapFrom(src => src.DateCreated));
And here is my error message:
"Custom configuration for members is only supported for top-level individual members on a type."
The problem, I think, has something to do with the fact that I'm trying to map the nested property SerialNumberName from Box > SerialNumbers to the nested property Name from BoxedElectrodesRowModel > SerialNumbers.
How do I go about fixing this?