I have a model for my table OWNER
namespace MyApp.Models
{
public partial class Owner
{
public int owner_id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string address { get; set; }
public string city { get; set; }
public virtual User User { get; set; }
}
}
and then i have my ViewModel
public partial class OwnerData
{
public string firstname { get; set; }
public string lastname { get; set; }
public string address { get; set; }
}
My Controller
public ActionResult Index()
{
//Create the object Owner based on the User Identity
Owner owner = CustomDbFunctions.GetUserEntity(User, db).Owner;
//New instance of the ViewModel
OwnerData ownerData = new OwnerData();
ownerData.lastname = owner.lastname;
ownerData.firstname = owner.firstname;
ownerData.address = owner.address;
return View(ownerData);
}
There's a simpler way in order to convert my owner into ownerData without rewrite evry single property of my object?