实体框架将父级与子网格加载到网格

时间:2012-12-12 03:49:42

标签: entity-framework entity-framework-4

您好我的架构edmx

enter image description here

我试试这个

protected void Page_Load(object sender, EventArgs e)
    {
         JeansEntities db = new JeansEntities();
         GridView1.DataSource = (db.Employes).Include("Address");
         GridView1.DataBind();
    }

这只给我Employe表数据...... 我不明白......

谢谢

1 个答案:

答案 0 :(得分:-1)

protected void Page_Load(object sender, EventArgs e)
    {
         using (JeansEntities db = new JeansEntities())
         {
            GridView1.DataSource = db.Employes.Select(p=> new { Id = p.Id, FirstName = p.FirstName, LastName = p.LastName, Street = p.Address.Street, Number = p.Address.Number, Country = p.Address.Country, Quarter = p.Address.Quarter }).ToList();
            GridView1.DataBind();
         }
    }