Please find code below:
public class CustomerDto
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public String Name { get; set; }
}
public class Customer
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public String Name { get; set; }
}
// ...
var customers = _context.Customers.ToList();
var cusDtos= Mapper.Map<List<Customer>,List<CustomerDto>>(customers);
return cusDtos;
All objects in cusDtos
have value for all property except Id
, Id
is 0 for all objects. customers contains value for Id
, but after mapping the Id
becomes 0.
Can anyone please help me to solve this issue?
Thanks in advance.