I have tested the following LINQ query in LINQPad. But it gives me this error:
Error Compiling Expression: Error Compiling Expression: The best overloaded method match for 'string.Contains(string)' has some invalid arguments Argument '1': cannot convert from 'System.Linq.IQueryable' to 'string'
(from t in db.ASN_ITEM
join t0 in db.ASN_MASTER on t.AWB_NO equals t0.AWB_NO
join t1 in db.ITEM_MASTER on t.ITEM_MASTER.ITEM_CODE equals t1.ITEM_CODE
where
(t.TOT_QTY - t.SCND_QTY) != 0 &&
!t.AWB_NO.Contains((from t2 in db.ASN_ITEM
where
t2.SCAN_STAT != 2
select new {
t2.AWB_NO
}).Distinct()) &&
t.AWB_NO == "E1000001"
select new {
t.AWB_NO,
ASN_DATE = t.REC_DATE,
t.PALLET,
t.CARTON,
t.TOT_QTY,
t.SCND_QTY,
VAR_QTY = (System.Int32?)(t.SCND_QTY - t.TOT_QTY),
REMARKS =
(t.TOT_QTY - t.SCND_QTY) == 0 ? "No Variance" :
(t.TOT_QTY - t.SCND_QTY) > 0 ? "Less Qty" :
(t.TOT_QTY - t.SCND_QTY) < 0 &&
t.TOT_QTY != 0 ? "Excess Qty" :
t.TOT_QTY == 0 &&
t.SCND_QTY != 0 ? "Excess Item" : null,
t1.PART_NO
}).Distinct()
I got this error, when I give below condition in where clause:
!t.AWB_NO.Contains((from t2 in db.ASN_ITEM
where
t2.SCAN_STAT != 2
select new {
t2.AWB_NO
}).Distinct())
Actually in SQL query, this is what I needed (below):
WHERE ASN_ITEM.AWB_NO NOT IN (SELECT DISTINCT AWB_NO FROM ASN_ITEM WHERE SCAN_STAT !=2 )