Bir özelliği bir nesneden farklı bir özellik adıyla başka bir nesneye nasıl eşleyebilirim? Farklı özellik adlarına sahip nesneler arasında eşleşme için ValueInjecter kullanma
Şöyle birProduct
sınıf var:
public class Product : IEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
Ve benzeri görünüm modeli görünür:
Product.Id => ProductSpecificationAddViewModel.ProductId
Product.Name =>ProductSpecificationAddViewModel.ProductName
: Aşağıdaki eşleme yapmak gerekir
public class ProductSpecificationAddViewModel
{
public int ProductId { get; set; }
public string ProductName { get; set; }
}
İşte benim hareket yöntemim:
public ActionResult Add(int id)
{
Product product = productService.GetById(id);
// Mapping
//ProductSpecificationAddViewModel viewModel = new ProductSpecificationAddViewModel();
//viewModel.InjectFrom(product);
return View(viewModel);
}
Bunu nasıl yaparım?
ConventionInjection çalışmaz çünkü –