Linq query

Associate
Joined
27 Jan 2005
Posts
1,347
Location
S. Yorks
Am a bit confused by LINQ but have created the following where clause but it doesn't work:

Code:
results = results.AsQueryable().Where(x =>
            x.Site == frmCarriageCoster.intCompSite &&
            x.txtPostcodeSubArea == strRet &&
            x.txtItemTypeDescription == "Pallet" &&
            x.MinWeight <= wgt &&
            x.txtDOWDescription == DoW &&
            x.MaxQty > ((frmCC.txtTWgt / x.MaxQty) / x.MaxWeight) &&
            x.MinQty < ((frmCC.txtTWgt / x.MaxQty) / x.MaxWeight));

It worked fine until I added the final 2 lines, any ideas?

regards,

Matt
 
Why does it not work - nothing returned or an error?

My guess would be that the calculation in the last clauses isn't giving the value you think it is.

Try running the '((frmCC.txtTWgt / x.MaxQty) / x.MaxWeight)' calc in the immediate window to see what value it generates and then check the DB manually.
 
You should also, for the sake of future maintenance, break up the linq queries.

Code:
results = results.AsQueryable()
            .Where(x => x.Site == frmCarriageCoster.intCompSite)
            .Where(x.txtPostcodeSubArea == strRet)
            .Where(x => x.txtItemTypeDescription == "Pallet")
            .Where(x => x.MinWeight <= wgt)
            .Where(x => x.txtDOWDescription == DoW)
            .Where(x => x.MaxQty > ((frmCC.txtTWgt / x.MaxQty) / x.MaxWeight))
            .Where(x => x.MinQty < ((frmCC.txtTWgt / x.MaxQty) / x.MaxWeight));
Much more readable, and much easier to test which criterion works, and which doesn't.
 
Back
Top Bottom