实体框架 4 未正确绑定到 datagridview

发布于 2025-01-02 16:49:38 字数 1136 浏览 5 评论 0原文

我运行以下代码:

    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();

并得到了相同的结果。

Im running the following code :

    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;
    }

But instead of giving me the entity collection of nicks, each one with field of "Value" it gives this inside the datagrid view...

enter image description here

The tables definately have the data and I have used EF in a previous project fine and it did not behave like this.. so I have no idea why.

The edmx is like so :

enter image description here

EDIT:

I tried

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

And got the same result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2025-01-09 16:49:38

你缺少一个投影:

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();

You're missing a projection:

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文