I'm working on creating a SQL view and ultimately, I would like to add the view to my Entity Framework model. I understand that this can simply be done in Entity Framework but I am just experimenting with views and need to work on my SQL skills.
Let's imagine a scenario where I am pulling data from a table called Sates. State has a 0->n association to another table called City. City has a 0-n association to another table called Streets.
So my script would be something similar to:
SELECT st.Name, st.ID FROM Test.States s
LEFT OUTER JOIN Test.Cities c on c.StateID = s.ID
LEFT OUTER JOIN Test.Streets str on str.CityID = c.ID
What do I need to add to the View script to grab all the corresponding Cities and Streets in the hierarchy shown below? I basically want my View entity to have the Cities and Streets collections populated:
public partial class StateView
{
public string Name { get; set; }
public long ID { get; set; }
public ICollection<City> Cities { get; set; }
}
public partial class City
{
public string Name { get; set; }
public long ID { get; set; }
public ICollection<Street> Streets { get; set; }
}
P.S. my goal here is to make one trip to the DB, Thank you in advance!