I am trying to map an Entity Framework Code First class to a WCF DataContract class using AutoMapper.
The code is as follows:
[DataContract]
public class User
{
[DataMember]
public int UserId { get; set; }
[DataMember]
public string UserName { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public string Email { get; set; }
[DataMember]
public DateTime DateCreated { get; set; }
[DataMember]
public int RoleId { get; set; }
}
public class User1
{
public int UserId { get; set; }
[StringLength(255, MinimumLength = 3)]
public string UserName { get; set; }
[StringLength(255, MinimumLength = 3)]
public string Password { get; set; }
[StringLength(255, MinimumLength = 3)]
public string Email { get; set; }
public DateTime DateCreated { get; set; }
public int RoleId { get; set; }
[ForeignKey("RoleId")]
public virtual Role Role { get; set; }
}
public static T Get<T>(this object source) where T : class
{
Mapper.CreateMap(source.GetType(), typeof(T));
T destination = default(T);
Mapper.Map(source, destination);
return destination;
}
User user = new User();
User1 user1 = user.Get<User1>();
I am getting this exception while executing the last line in above code:
Missing type map configuration or unsupported mapping.
Mapping types: Object -> User
System.Object -> DataLayer.UserDestination path: User
Source value: Service.User
Can anyone help in getting this resolved?