0

我有一个行表和一个标签表。每行可能有来自标签表的多个标签。我试图建立一个包含所有标签的清单,并有一个复选框,显示该行是否具有该标签,如果它已检查。

我已经将数据网格视图设置为 2 列。一个绑定到 Name,另一个 checkboxcell 绑定到 IsTagged

我试图为此使用投影:

-> line comes into constructor
var tagsList = from t in rs.Tags select new { Name = t.Name, IsTagged = line.Tags.Where(x => x.Name == t.Name).Any() };
dgvTags.DataSource = tagsList;

我的实体图如下:

在此处输入图像描述

更新 :

我重新做了整个事情,从 2005 年将后面的 db 升级到 2008r2,现在它似乎可以工作但给出以下错误......它不会崩溃但在数据网格中没有显示任何项目。

在此处输入图像描述

4

1 回答 1

0

I think the problem is due to using the line parameter's collection in your linq-to-entities query.

I would try rewriting the query to only use the primitive types like this:

var tagNames = line.Tags.Select(x => x.Name).ToList();
var tagsList = from t in rs.Tags 
               join n in tagNames on t.Name equals n into tags
               select new 
               {
                 Name = t.Name, 
                 IsTagged = tags.Any() 
               };
于 2012-04-20T16:36:23.770 回答