How to automap this(mapping sub members)

I have something like this

public class ProductViewModel
{
  public int SelectedProductId { get; set; }
  public string ProductName {get; set;}
  public int Qty {get; set;}
   public List<SelectListItem> Products { get; set}; 
}

I have a domain like this

public class Product
{
  public int ProductId {get; set;}
  public string ProductName {get; set;}
  public int Qty {get; set;}
}


public class Store
{
  public Product() {get; set;}
}

Now I need to do the mapping.

// in my controller

var result = Mapper.Map<ProductViewModel, Store>(Product);

this won't bind anything since it can't figure out how to put the ProductId in since it is

Store.Product.ProductId;

My map is like this

Mapper.CreateMap<ProductViewModel, Store>().ForMember(dest => dest.Product.ProductId, opt => opt.MapFrom(src => src.SelectedProductId));

I get this error

Expression 'dest => Convert(dest.Product.SelectedProductId' must resolve to top-level member. Parameter name: lambdaExpression

Я не знаю, как это сделать.

11
задан chobo2 8 February 2011 в 17:12
поделиться