Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

LINQ, WHERE clause issue

Question: Why lines 5 and 6 giving me trouble?

How can I fix this. I have used this sort of syntax for years in SQL work. What is the equivalent in LINQ (vb.net)?
            Dim ODs = (From od In db.tblOrderDetails Join o In _
                               db.tblOrders On od.OrderID Equals o.OrderID Join c In _
                               db.tblCustomers On o.CustomerID Equals c.CustomerID Join s In _
                               db.tblSoftwares On od.SoftwareID Equals s.SoftwareID _
                               Where o.OrderID = IIf(intOrderID = 0, o.OrderID, intOrderID) And _
                                o.CustomerID = IIf(intCustID = 0, o.CustomerID, intCustID) _
                               Order By c.FirstName & " " & c.LastName _
                               Select CustName = c.FirstName & " " & c.LastName, _
                                      od.OrderID, o.OrderDate, s.Title, od.Quantity, s.UnitPrice, Sub_Total = od.Quantity * s.UnitPrice).ToArray()

Open in new window


Please see: http://developwith.net/2012/07/20/where-if-and-where-iif-linq/ if it could help. I may need some help in its implementation.
ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the error?
Avatar of Mike Eghtebas

ASKER

kaufmed,

My apology for not responding earlier. It didn't like IIF() syntax. I do not recall exact description. I have revised the solution since. But later I will try the solution from louisfr which seems a working solution.

Thanks,

Mike