【问题标题】:Entity Framework load Parent whit childs to grid实体框架将父级与子级加载到网格
【发布时间】:2012-12-12 12:20:06
【问题描述】:

你好,这是我的架构 edmx

我试试这个

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

这给了我雇员表数据... 没看懂……

谢谢

【问题讨论】:

  • 您希望两个表中的字段都显示在 GridView 中?
  • 是的,这就是我这样做的原因 (db.Employes).Include("Address");

标签: entity-framework entity-framework-4


【解决方案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();
         }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多