How to fetch data with EF on one to many relationship.
i.e if i have a table name Person(personID as primary key) and another table name streetLivedIn(personID as foreign key).
Now i force my controller method to pass an object of type person
var persons=db.persons();
return View(persons);
Now i want to display Person details along with street(i.e that what stored at streetLivedInTable) he/she lived at.
suppose i have an Entityset of person
public class Persons
{
public string Name{get;set;}
//NAVIGATIONL PROP.
public virtual ICollection<streetLivedIn>{get;set}
}
Suppose the navigational property name is
Streets.Then you can use the
Includemethod to eager load this property.You can display this in various ways. Eg
Or you can use the
WebGrid,MvcContrib Grid, etc