Automapping issue

Hi,
I’m trying to replace Automapper with ServiceStack’s automapper but i am having issues with converting lists as ConvertTo is not available / it’s not happy converting one type to another. Would you have any pointers for me?
thanks

public List<MemberModel> GetMembers(string sortExpression)
{
    var members = client.Get<List<Member>>(new MembersRequest { SortExpression = sortExpression });

    return members.ConvertAll(x => x.ConvertTo<MemberModel>());  // .ConvertTo not accessible
    //return Mapper.Map<List<Member>, List<MemberModel>>(members);  
}

// Other classes for reference below

using System;
using System.Collections.Generic;
using System.Text;

namespace WinFormsApp.Models
{
    public class MemberModel
    {
        public MemberModel()
        {
            Orders = new List<OrderModel>();
        }
        public int MemberId{ get; set; }
        public string Email { get; set; }
        public string CompanyName{ get; set; }
        public string City{ get; set; }
        public string Country { get; set; }

        public IList<OrderModel> Orders { get; set; }
    }
}
using BusinessObjects.BusinessRules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessObjects
{

    public class Member
    {
        public Member()
        {
        }
	
        public int MemberId { get; set; }

        public string Email { get; set; }
        public string CompanyName { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public int NumOrders { get; set; }
        public DateTime LastOrderDate { get; set; }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BusinessObjects.RequestObjects
{
	[Route("/Members/{SortExpression}", Verbs = "GET")]
	[Route("/Members/{WithOrder}/{SortExpression}", Verbs = "GET")]
	public class MembersRequest: IReturn<List<Member>>
	{ 
		public string SortExpression { get; set; }
		public bool WithOrder { get; set; }
	}
}

What is the type of members?

var members = client.Get<List<Member>>(new MembersRequest { SortExpression = sortExpression });

Is it List<Member>? i.e:

List<Member> members = client.Get<List<Member>>(new MembersRequest { SortExpression = sortExpression });

Because I’m not seeing any build errors in that case.

I’d check to make sure you’re referencing ConvertTo<T> properly, it’s in the ServiceStack namespace of the ServiceStack.Text.dll. Make sure ConvertTo<T> is an extension method of the AutoMappingUtils static class and not something else.

Got it, thanks. Didn’t have .Text installed in the client project!

1 Like