【问题标题】:Entity framework 4 not binding properly to datagridview实体框架 4 未正确绑定到 datagridview
【发布时间】:2012-02-27 01:29:53
【问题描述】:

我正在运行以下代码:

    private void btnMatchFull_Click(object sender, EventArgs e)
    {
        Match m = Regex.Match(txtIP.Text, "(?<HostIP>[A-Z0-9.]{13}).(?<SubIP>[A-Z0-9.]{13})");
        string host = m.Groups["HostIP"].Value;
        string sub = m.Groups["SubIP"].Value;

        var abc = (from x in _db.HostIPs
                  where x.Value == host
                  from s in x.SubIPs
                  where s.Value == sub
                  select s.Nicks).ToList();

        dgvNicks.DataSource = abc;
    }

但不是给我尼克的实体集合,而是每个具有“值”字段的实体集合,它在数据网格视图中给出这个......

这些表肯定有数据,我在以前的项目中使用过 EF,但它的行为不是这样。所以我不知道为什么。

edmx 是这样的:

编辑:

我试过了

var abc = (from x in _db.HostIPs
                      where x.Value == host
                      from s in x.SubIPs
                      where s.Value == sub
                      select s.Nicks).ToList();

得到了同样的结果。

【问题讨论】:

  • 如果你 ToList() 并将它绑定到 DataGrid 会发生什么?应该知道问题是 EF 还是其他地方。

标签: c# linq data-binding entity-framework-4 datagridview


【解决方案1】:

你错过了一个投影:

var abc = (from x in _db.HostIPs
           where x.Value == host
           from s in x.SubIPs
           where s.Value == sub
           from n in s.Nicks
           select n).ToList();

【讨论】:

    猜你喜欢
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    相关资源
    最近更新 更多