2013-06-20 22 views
-1

我收到异常,当我尝试循环到一个集合。该方法或操作没有在集合中使用LINQ

//代码

fieldFormatDropDown.DataSource = From FieldFormatLinq In fieldFormatsCollection Where FieldFormatLinq.DataTypeId = dataTypeId And FieldFormatLinq.IsActive = True 

//异常:

The method or operation is not implemented 

为什么我得到这个?

+0

什么是'fieldFormatsCollection'的类型?请发布异常的堆栈跟踪。 –

+0

问同一个问题[here](http://social.msdn.microsoft.com/Forums/vstudio/en-US/843638c5-277b-40bd-b016-89050e2b7c61/unhandled-exception-the-method-or- operation-is-not-implemented-),在将它分配给'DataSource'之前,尝试将'IEnumerable'转换为'List'。 – jbabey

+0

您应该几乎总是使用'AndAlso'而不是'And'和'OrElse'而不是'Or'。 –

回答

1

尝试转换为Tolist()

//代码

fieldFormatDropDown.DataSource = (From FieldFormatLinq In fieldFormatsCollection Where FieldFormatLinq.DataTypeId = dataTypeId And FieldFormatLinq.IsActive = True).ToList() 
+0

这应该解决问题,因为DataSource必须实现IListSource。但是,我更喜欢VB.NET中的两行:'Dim query = From ....'和'fieldFormatDropDown.DataSource = query.ToList()' –