We have two models vw_fleet and fleet_contact generated by the entity framework. We are using views to retrieve data and we can't define the relationship between those models but when we retrieve data for fleet_contact we need fleet information as well.
public partial class vw_fleet
{
public int account_id { get; set; }
public int fleet_id { get; set; }
public string fleet_name { get; set; }
}
public partial class fleet_contact
{
public int id { get; set; }
public int fleet_id { get; set; }
public string contact { get; set; }
}
We have added a property(Fleet) to fleet_contact
public partial class fleet_contact
{
public vw_fleet Fleet { get; set; }
}
One way to do that is by using join.
using (var context = new EFEntities())
{
return context.fleet_contact.Join(context.vw_fleet, fc => fc.fleet_id, f => f.fleet_id, (fc, f) => new FleetContactModel()
{
fleet_id = fc.fleet_id,
Fleet = f,
contact = fc.contact,
id = fc.id,
}
).ToList();
}
Is there any way to achieve the above solution.