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; }
}
}