Finding a list of objects in a list of objects using linq in VB.net

I have 2 classes

Public Class Shipper Public Property ShipperID As Long Public Property CreateDate As DateTime Public Property ShipperCode As String Public Property ShipperName As String Public Property ShippingMethods As List(Of ShippingMethod) Public Class ShippingMethod Public Property ShippingMethodID As Long Public Property ShipperID As Long Public Property CreateDate As DateTime Public Property ShipppingMethod As String Public Property ShipppingMethodCode As String 

I am trying to find the sender list where shippercode is empty and ShipperName is not empty - I got this

 Dim oListShipper As List(Of Shipper) = GetAllShippers() Dim oListShipperRet As List(Of Shipper) = _ oListShipper.FindAll(Function(c) (c.ShipperCode = "" And _ c.ShipperName <> "")) 

Now, how to get all senders where ShippingMethod.ShipppingMethodCode = '' and ShippingMethod.ShipppingMethod <> ''

I tried

 oListShipper.FindAll(Function(c) (c.ShipperCode = "" And _ c.ShipperName <> "")) Or _ (c.ShippingMethods.FindAll(Function(d) d.ShipppingMethodCode = "" And _ d.ShipppingMethod <> "").Count > 1))) 

But it didn’t work out. Any idea?

Thanks Jothish

+4
source share
1 answer

I believe the FindAll method is directly related to the List class and is not part of LINQ. Instead, try using the Where and Any methods. My VB skills are rusty, but I think it will be something like this:

 Dim oListShipper As List(Of Shipper) = GetAllShippers() Dim oListShipperRet As List(Of Shipper) = oListShipper .Where(Function(c) (c.ShipperCode = "" And c.ShipperName <> "") OR (c.ShippingMethods.Any( Function(d) d.ShipppingMethodCode = "" And d.ShipppingMethod <> "") )) .ToList(); 
+5
source

Source: https://habr.com/ru/post/1333077/


All Articles