我有以下代码: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get all the live orders and extract their mfrs' Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building) Dim unavailableM
Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get all the live orders and extract their mfrs' Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building) Dim unavailableMfrs As New List(Of Manufacturer) For Each so As StockingOrder In sos unavailableMfrs.Add(so.Source) Next 'then remove all mfrs with an open SO from a list of all mfrs' Dim allMfrs As List(Of Manufacturer) = Manufacturer.GetManufacturers Return allMfrs.Except(unavailableMfrs) <----- error here End Function
解释上面做了什么:
> GetFormsByStatus()不言自明
> GetManufacturers()返回数据库中所有制造商的列表
我想获得制造商的想法是获取我的开放表格中所有制造商的清单,然后获得所有制造商的清单,并排除第一个清单中的所有制造商,如图所示(伪):
List A: {1,2,3,4,5,6,7,8,9,10} List B: {5,7,10} Result: {1,2,3,4,6,8,9}
我已根据this article设置了我的制造商类,以便可以进行比较,但我仍然收到此错误:
Unable to cast object of type ‘
<ExceptIterator>d__92'1[csCore.Manufacturer]'
to type ‘System.Collections.Generic.List'1[csCore.Manufacturer]
‘.
我一开始认为,因为在测试期间GetFormsByStatus()返回0结果可能会导致问题,但如果提供的列表有0项,则Except()不起作用是没有意义的.谁能发现我做错了什么?
非常感谢!
该函数需要List(Of Manufacturer)返回类型,而不是IEnumerable(Of Manufacturer),因此在返回值中添加.ToList()应修复它:Return allMfrs.Except(unavailableMfrs).ToList()