Dim tenItem = From t In _InvalidFeeList _
From i In ItemCount _
Where t.FeeCode <> i.FeeCode _
Order By t.Description _
Ascending Take (10)
Dim feeList As List(Of AccessorialFee) = tenItem.ToList()
I am getting "Can not convert to System.generic.list" error. I look all over for this error and it seem like my code should work for example here
I don't get it. Can someone tell me where i got it wrong?
edit: I think i should explain what I'm trying to do here. I want to compare two object list and select the object from the InvalidFeeList if the FeeCode is not equal to the object in ItemCount FeeCode and take the first 10 objects from the InvalidFeeList.
-
_InvalidFeeList is not of type List(Of AccessorialFee)
[Edit] Try this and add a breakpoint and a watch:
Dim tenItem = (From t In _InvalidFeeList _ From i In ItemCount _ Where t.FeeCode <> i.FeeCode _ Order By t.Description _ Ascending Take (10)).ToList().GetType()
Jack : You're correct. ThankJack : I don't think that was it. I do have _InvalidFeeList declare as type of List(Of AccessorialFee)hypoxide : See edit above.hypoxide : We want to be sure that the tenItem list is actually an AccessorialFee list after the linq has executed. -
The problem is that you've got two "From" clauses, so the result isn't just the type of the original collection. It's easy to fix though - just add a projection at the end:
Dim tenItem = From t In _InvalidFeeList _ From i In ItemCount _ Where t.FeeCode <> i.FeeCode _ Order By t.Description _ Ascending Take (10) _ Select t ' This is the new line ' Dim feeList As List(Of AccessorialFee) = tenItem.ToList()
EDIT: Are you trying to find items in
_InvalidFeeList
whoseFeeCode
isn't present in any item inItemCount
? If so, I suggest this change:Dim feeCodes = From i In ItemCount Select i.FeeCode Dim feeCodeSet = new HashSet(Of FeeCodeType)(feeCodes) Dim tenItem = From t in _InvalidFeeList Where Not feeCodeSet.Contains(t.FeeCode) Order By t.Description _ Ascending Take (10) Dim feeList As List(Of AccessorialFee) = tenItem.ToList()
As you can see, I didn't know the type of
FeeCode
, and VB is not exactly my strong point, but I hope you get the general idea. This suggestion is assuming you're using LINQ to Objects - if you're using LINQ to SQL I'm not sure of the best way to do it. Note that we no longer need theSelect
clause fortenItem
as we're only dealing with a single collection now.Jack : That was it. Thank you.Jack : One problem, the selected t have the same feedcode as i in ItemCount. It didn't select the different object in _InvalidFeeListJon Skeet : The same code as *which* i? You're effectively joining against *all* the values of i in ItemCount. If there are two different values for FeeCode in ItemCount, you'll get every t in _InvalidFeeList_, potentially multiple times. What are you really trying to do?Jack : Your assumption is correct. I'm trying to find the item whose FeeCode is not in any item in ItemCount. I'll try your suggestion. Thank a lot. I'll try to be more clear, next time.
0 comments:
Post a Comment