I have an problem in my ASP.net MVC Application.
How Can i map my Model to my ViewModel (with navigation propery as a collection)?
Sorry for uppcase, but it's Database first approach, and I can't change names in database
Model:
public partial class DB_USER
{
public int ID { get; set; }
public string FIRST_NAME { get; set; }
public string LAST_NAME { get; set; }
public virtual ICollection<DB_CUSTOMER_USER> DB_CUSTOMER_USER { get; set; }
public virtual ICollection<DB_USER_PHONES> DB_USER_PHONES { get; set; }
}
public partial class DB_CUSTOMER_USER
{
public int USER_ID { get; set; }
public string CUSTOMER_MODULO { get; set; }
public decimal ID { get; set; }
public virtual DB_USER DB_USER { get; set; }
}
public partial class DB_USER_PHONES
{
public string PHONE { get; set; }
public int USER_ID { get; set; }
public virtual DB_USER DB_USER { get; set; }
}
And i made this viewmodel (i hope is correct).
public class UserData
{
public int ID { get; set; }
public string FIRST_NAME { get; set; }
public string LAST_NAME { get; set; }
public virtual ICollection<UserCustomer> UserCustomer { get; set; }
public virtual ICollection<UserPhone> UserPhones { get; set; }
}
public class UserCustomer
{
public int USER_ID { get; set; }
public string CUSTOMER_MODULO { get; set; }
public decimal ID { get; set; }
public virtual UserData UserData { get; set; }
}
public class UserPhone
{
public string PHONE { get; set; }
public int USER_ID { get; set; }
public virtual UserData UserData { get; set; }
}
I need to send these data to view as a viewmodel and i this the best way would be use AutoMapper.