public class ClientViewModel
{
[Required(ErrorMessage = "The Client Code field is required.")]
public string ClientCode { get; set; }
[Required(ErrorMessage = "The Company Legal Name field is required.")]
public string CompanyLegalName { get; set; }
public string Notes { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public Nullable<DateTime> ScheduledDate { get; set; }
public Nullable<decimal> AmountDiscount { get; set; }
}
public class Client
{
public string ClientCode { get; set; }
public string CompanyLegalName { get; set; }
public string Notes { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
public Nullable<DateTime> ScheduledDate { get; set; }
public Nullable<decimal> AmountDiscount { get; set; }
}
Edit:
Exception Details: AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types: Client -> ClientViewModel myapp.Models.Client -> myapp.Models.ClientViewModel
Destination path: ClientViewModel
Source value: myapp.Models.Client
My Client
& ClientViewModel
has exact same number of props and below is my code that I'm using and its throwing error without getting much information, what I'm missing here?
Client client = context.Clients.Where(x => x.CustomerID == id).FirstOrDefault();
ClientViewModel clientViewModel = Mapper.Map<Client, ClientViewModel>(client);
An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code
DateTime?
andNullable<DateTime>
when you can use onlyDateTime?
? – aloisdgNullable
to?
thats what i have done but nothing has changed and I put it back and now I have the exact same copy but still the same error – Nick KahnClient
class is generated so I have tried to change?
on ClientViewModel but since I was getting the same error so I revert back the same asClient
– Nick Kahn[Required]
? I tested it without and it worked great. – aloisdg