Guest User

Guest User

  • Tech Writer
  • 62
  • 3.6k

Mappint 2 or more entities into 1 model (Not AutoMapper)

Nov 21 2019 6:52 PM
I have 2 entities which the People and Contact
  1. public class People{  
  2. [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  3. public Guid Id { getset; }  
  4. public string FirstName { getset; }  
  5. public string LastName { getset; }  
  6. }  
  7. public class Contact{  
  8. [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  9. public Guid Id { getset; }  
  10. public Guid PeopleId { getset; }  
  11. public string Type { getset; }  
  12. public string ContactNumber { getset; }  
  13. }
and I have the model ContactModel to display the entity.
  1. public class ContactModel{  
  2. public Guid Id { getset; }  
  3. public Guid PeopleId { getset; }  
  4. public string FirstName { getset; }  
  5. public string LastName { getset; }  
  6. public string Type { getset; }  
  7. public string ContactNumber { getset; }  
  8. }  
my problem is when I'm trying to map the entities to model, I can only map the People entity or one entity and the the two entities.
  1. public static ContactModel ToModel(this People people){  
  2. return new ContactModel{  
  3. Id = people.Id,  
  4. FirstName = people.FirstName,  
  5. LastName = people.LastName  
  6. };  
  7. }  

Answers (5)