paulthepaddy
Well-known member
Hi guys, got my lambda expression fixed as in i didn't need them, never realized i could use two arguments for comparison.
I have a CheckedListBox, that holds a Collection of Cars, And a DataGridView That Displays The Cars.Orders
The Problem i am getting, is the a common problem, that people are complaining that you cant use a Where Clause with an Include Statement(lots of hours googling & trying & failing)
After getting my list of cars, it is displaying ALL orders related to that car.
Here is code i have been trying and messing with to no avail
I have a CheckedListBox, that holds a Collection of Cars, And a DataGridView That Displays The Cars.Orders
The Problem i am getting, is the a common problem, that people are complaining that you cant use a Where Clause with an Include Statement(lots of hours googling & trying & failing)
After getting my list of cars, it is displaying ALL orders related to that car.
VB.NET:
Dim listofcars = From car As Car In db.Cars, Ord As Order In car.Orders Where car.FullyPaid = False AndAlso Ord.Department_ID = invoice.Department_ID AndAlso Ord.Invoiced = False Select car
Here is code i have been trying and messing with to no avail
VB.NET:
'Tried to get a new list of cars and loop through to remove orders(didn't work, stopped because collection was edited)
Dim listofcars = (From car As Car In db.Cars, Ord As Order In car.Orders Where car.FullyPaid = False AndAlso Ord.Department_ID = invoice.Department_ID AndAlso Ord.Invoiced = False Select car).ToList
'For Each Car As Car In listofcars
' 'Loops through the orders to check if they are suitable for invoicing
' For Each Ord As Order In Car.Orders
' If Ord.Department_ID <> invoice.Department_ID Then
' Car.Orders.Remove(Ord)
' Continue For
' End If
' If Ord.Invoiced = True Then
' Car.Orders.Remove(Ord)
' Continue For
' End If
' Next
' 'Checks for any orders remaining after filtering
' If Not Car.Orders.Any Then listofcars.Remove(Car)
'Next
'Dim query = db.Orders.Where(Function(ord As Order) ord.Invoiced = False AndAlso ord.Department_ID = invoice.Department_ID)
'Dim query = From Car As Car In db.Cars
' Where Car.FullyPaid = False _
' Select New Car With {.Reg = Car.Reg, .Make = Car.Make, .Model = Car.Model, .Colour = Car.Colour, .AmountTotal = Car.AmountTotal _
' , .AmountDue = Car.AmountDue, .AmountPaid = Car.AmountPaid, .FirstCreatedDate = Car.FirstCreatedDate, _
' .LastEditDate = Car.LastEditDate, .FullyPaid = Car.FullyPaid, _
' .Orders = (From Ord In Car.Orders Where Ord.Invoiced = False AndAlso Ord.Department_ID = invoice.Department_ID Select New With{Key )}
Didn't Work, Cant Compair Boolean? with Boolean(dont know why
Dim query = db.Cars.Where(Function(c) c.FullyPaid = False).Select(Function(c) New With {Key .car = c, Key .Orders = _
c.Orders.Where(Function(ord) ord.Department_ID = invoice.Department_ID)})
Dim results = query.ToList()
Dim products = results.Select(Function(x) x.car)
Last edited: