我对DataGridViewRowCollection上的LINQ查询有点神秘。这里是我的查询(其中“网格”是一个DataGridView对象):LINQ to DataGridViewRowCollection
var rows = from DataGridViewRow row in grid.Rows
where row.Selected
select row;
我有一个包含此查询一个项目,它完美地被执行。问题是,在另一个项目中,我得到以下错误,当我尝试构建解决方案:
error CS1936: Could not find an implementation of the query pattern for source type 'System.Windows.Forms.DataGridViewRow'. 'Where' not found.
起初我还以为这是一个参考的问题,但我使用在两个项目中相同的参考:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.EntityModel;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Diagnostics;
没有人有任何想法,为什么我的LINQ查询将在一个项目工作,而不是其他?
编辑1:
为了记录在案,这里是确切的上下文在查询是工作:
public List<Int64> ComponentIDs
{
get
{
return
(
from DataGridViewRow row in grid.Rows
where row.Selected
select (Int64)row.Cells[0].Value
).ToList();
}
}
编辑2:
我只是碰到以下link ...看到接受的答案...这就是我想要做的。出于某种原因,我无法使IEnumerable.Cast()扩展方法正常工作......我错过了什么?
你确定你有* *正好在这两个地方同样的LINQ查询? (顺便说一句,那些使用的是指令,而不是引用,名称空间和程序集之间有很大的区别。) – 2012-02-08 14:33:51
谢谢,Jon纠正了我对“reference”这个词的不正确使用! =)是的,我在两个地方都使用完全相同的LINQ查询。我必须承认这很令人困惑。 – HydroPowerDeveloper 2012-02-08 14:46:54
[在LINQ中使用DataGridViewRowCollection对象]可能的重复(http://stackoverflow.com/questions/2648657/using-datagridviewrowcollection-object-in-linq) – KyleMit 2016-04-11 20:29:46