简体   繁体   English

实体框架投影崩溃VS

[英]Entity Framework Projection Crashing VS

I have a lines table, and a tags table. 我有一个线表和一个标签表。 Each line may have multiple tags from the tags table. 每行可能有来自标签表的多个标签。 Im trying to build a checklist, with all the tags, and have a checkbox that shows if that line has that tag, if it does its checked. 我试图建立一个带有所有标签的清单,并有一个复选框,显示该行是否具有该标签(如果已选中)。

Ive set the datagrid view with 2 columns. 我已经用2列设置了datagrid视图。 one bound to Name and another checkboxcell bound to IsTagged 一个绑定到Name,另一个checkboxcell绑定到IsTagged

Im trying to use a projection for this : 我试图为此使用投影:

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

My entity diagram is as below : 我的实体图如下:

在此处输入图片说明

UPDATE : 更新:

I re-did the whole thing, upgraded the back db to 2008r2 from 2005, now it seems to work but gives the following error... which doesnt crash but shows no items in the datagrid. 我重新做了整个工作,将后台数据库从2005年升级到2008r2,现在它似乎可以工作,但是给出了以下错误...不会崩溃,但在datagrid中没有显示任何项目。

在此处输入图片说明

I think the problem is due to using the line parameter's collection in your linq-to-entities query. 我认为问题是由于在linq-to-entities查询中使用了line参数的集合。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM