I wanted to understand the correct why to call two table in a model structure. Lets call table one car with carid, carmodel and carmanufacturersid. The next table we have manufacturers that has manufacturersid and manufacturersname. So I like to pull out carmodel and manufacturersname. So in the model for car do I add the model for manufacturers like public IEnumerable manufacturersname { get; set; }?
public class car
{
public int carId { get; set; }
public string carmodel { get; set; }
public int carmanufacturersid { get; set; }
//public IEnumerable<manufacturer> manufacturersname { get; set; }
public Model.manufacturer manufacturername{ get; set; }
}
public class manufacturer
{
public int manufacturerId { get; set; }
public string manufacturername{ get; set; }
}
public List<Model.car> GetAllCars()
{
using (var db = new Entities())
{
var cars = (from c in db.car
join m in db.manufacturersId on m.manufacturersId id equals c.manufacturersId
select new Model.car
{
carmodel = c.carmodel,
manufacturersname = m.manufacturersname
}
).ToList();
return cars;
}
}