help automapping using constructor IList<t> parameter to IList<string> parameter

29 views
Skip to first unread message

space...@gmail.com

unread,
Mar 12, 2018, 10:54:25 PM3/12/18
to AutoMapper-users
I need to automap BLTriangleStartupInfoModel  to  the TriangleStartUpInfoModel  class where TriangleStartUpInfoModel  is the source class..
The problem is the parameters between the classes are not a one to one match up, the paramters are lists, and one list parameter is contained in the TriangleStartUpInfoModel   but not in the TriangleStartUpInfoModel  class.
That parameter is used to set a child property.
Below is a listing of all the classes involve. 
I am not quite sure how to use the .ConstructUsing method to accomplish this.
I need to map a ILIst<string> to an IList<Row> where Row is class that contains a single property which is a string
I need to map a ILIst<int> to an IList<Column> where Column is class that contains a single property which is a int.
Any help would be appreciated.

Email me directly at stev...@mail.com if you a solution

    CreateMap<BLTriangleStartupInfoModel, TriangleStartUpInfoModel>()
                .ConstructUsing(x => new TriangleStartUpInfoModel(??????, ??????, new List<ILink>()));

   public class TriangleStartUpInfoModel : TriangleModel
        , ITriangleStartUpInfoModel
    {
        public IList<IRow> Rows { get; }
        public IList<IColumn> Columns { get; }

        public TriangleStartUpInfoModel(IList<IRow> rows
            , IList<IColumn> columns
            , IList<ILink> links = null) : base(links)
        {
            Rows = rows;
            Columns = columns;
        }
    }

public class BLTriangleStartupInfoModel : BLiModel
    , IBLTriangleStartupInfoModel
    {
      public  IList<string> Rows { get; }
      public  IList<int> Columns{ get; }
 

    public BLTriangleStartupInfoModel(IList<string> rows, IList<int> columns)
    {
        Rows = rows;
        Columns = columns;
    }
}

    public class BLiModel : IBLModel
    {

    }

 public class TriangleModel : TaskModel
        , ITriangleModel
    {

        public TriangleModel(IList<ILink> links) : base(links)
        {
        }
}

  public class TaskModel : IModel
    {
       public IList<ILink> Links { get; set; }

        public TaskModel(IList<ILink> links)
        {
            Links = links;
        }     
    }

    public class Row : IRow
    {
        public string RowValue { get; set; }
    }

    public class Column :IColumn
    {
        public int ColumnValue { get; set; }
    } 

Jimmy Bogard

unread,
Mar 13, 2018, 1:57:41 PM3/13/18
to automapper-users
For IList<T> to IList<string>, you just need a mapping from T to string. By default, this is just "ToString()" but that may not be sufficent.

--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

space...@gmail.com

unread,
Mar 13, 2018, 8:29:18 PM3/13/18
to AutoMapper-users
The problem is keep getting an error of Unmapped properties: Links when I try to map.
Below is the error.
I have tried several types of mapping but all give the same gd error.
I thought I had to do is ignore the list property but that did not work,

I tried this first and it gave is gd unmapp link error
       CreateMap<BLTriangleStartupInfoModel, TriangleStartUpInfoModel>()
            .ForMember(dest => dest.Rows, expression => Rows))
            .ForMember(dest => dest.Columns, expression => Columns))
            .ForMember(dest => dest.Links, expression => expression.Ignore());


I tried then tried this same  gd unmapp link error
   CreateMap<BLTriangleStartupInfoModel, TriangleStartUpInfoModel>()
            /ConstructUsing(x => new TriangleStartUpInfoModel(
               (IList<IRow>)x.Rows.Select(row => new Row { RowValue = row }).ToList().ToEnumerable()
             (IList<IColumn>)x.Columns.Select(col => new Column { ColumnValue = col }).ToList().ToEnumerable()
             new List<ILink>()));

I even tried the ResolvingUsing and it still gave the same error.

I am at a lost.

Error:
Unmapped members were found. Review the types and members below.
Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters
===========================================================================================================
BLTriangleStartupInfoModel -> TriangleStartUpInfoModel (Destination member list)
WebApi.Business.Layer.Models.Triangle.BLTriangleStartupInfoModel -> WebApi.Models.TriangleStartUpInfoModel (Destination member list)

Unmapped properties:
Links
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages