I'm a very beginner and I want to do something really simple, I guess I missed something but I could not find the answer.
I have two tables with many-to-many relationship mapped with EF4.1
public partial class Activity
{
public Activity()
{
this.Pack = new HashSet<Pack>();
}
public int ActivityId { get; set; }
public string Type { get; set; }
public string Title { get; set; }
public string Price { get; set; }
public virtual ICollection<Pack> Pack { get; set; }
}
public partial class Pack
{
public Pack()
{
this.Activity = new HashSet<Activity>();
}
public int PackId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Price { get; set; }
public virtual ICollection<Activity> Activity { get; set; }
}
And a context class generated:
public partial class EvgDatabaseEntities : DbContext
{
public EvgDatabaseEntities()
: base("name=EvgDatabaseEntities")
{
}
public DbSet<Pack> PackSet { get; set; }
public DbSet<Activity> ActivitySet { get; set; }
}
In my index view, I just need to display datas from a Pack, and activities related to this pack.
Here is the Controller :
public ActionResult Index()
{
var packs = evgDB.PackSet.Include("Activity").ToList();
return View(packs);
}
Here is what I would like to do in my view:
@model IEnumerable<myEvg.Models.EvgDatabaseEntities>
@{
ViewBag.Title = "Index";
}
@foreach (var pack in Model)
{
//SHOW PACK.ID PACK.DESCRIPTION
//SHOW THE ACTIVITIES RELATED TO THIS PACK
}
What is the best way/practice to do this ? I could do it by creating a third table in my EDM etc., but what is the point to have the possibility to make a native many-to-many relationship so ?
Sorry if it seems obvious to you, it's not to me, i'm just a beginner.