Linq Condition Addition

Hi Team,

I have one Linq as follows,
(From a In Sumif_DT.AsEnumerable()
Join b In MB52_Data_DT.AsEnumerable()
On a(“Material”).ToString.Trim Equals b(“Material”).ToString.trim And
a(“Plant”).ToString Equals b(“Plant”).ToString And
a(“Unit”).ToString Equals b(“Base Unit Of Measure”).ToString And a(“Storage Location”).ToString Equals b(“Storage Location”).ToString
Where CInt(a(“Quantity”).ToString) > CInt(b(“Unrestricted”).ToString)
Select notvalidmaterial_DT.Rows.Add({a(“Material”).ToString})
).ToList

Now i have to add one more condition to this linq, is like if any “Material” of Sumif_DT is not present in MB52_DT, then also i want that materials in notvalidmaterial_DT.

Please help.

Try with this query

(From a In Sumif_DT.AsEnumerable()
Group Join b In MB52_Data_DT.AsEnumerable()
On a(“Material”).ToString.Trim Equals b(“Material”).ToString.Trim And
a(“Plant”).ToString Equals b(“Plant”).ToString And
a(“Unit”).ToString Equals b(“Base Unit Of Measure”).ToString And a(“Storage Location”).ToString Equals b(“Storage Location”).ToString
Into Group
From b In Group.DefaultIfEmpty()
Where (b Is Nothing OrElse CInt(a(“Quantity”).ToString) > CInt(b(“Unrestricted”).ToString))
Select notvalidmaterial_DT.Rows.Add({a(“Material”).ToString})
).ToList

Cheers @yash.choursia

Hi @yash.choursia

Try this:

(From a In Sumif_DT.AsEnumerable()
Join b In MB52_Data_DT.AsEnumerable()
On a("Material").ToString.Trim Equals b("Material").ToString.Trim And
a("Plant").ToString Equals b("Plant").ToString And
a("Unit").ToString Equals b("Base Unit Of Measure").ToString And a("Storage Location").ToString Equals b("Storage Location").ToString
Where CInt(a("Quantity").ToString) > CInt(b("Unrestricted").ToString)
Select notvalidmaterial_DT.Rows.Add({a("Material").ToString})
Union
From a In Sumif_DT.AsEnumerable()
Where Not MB52_Data_DT.AsEnumerable().Any(Function(b) a("Material").ToString.Trim = b("Material").ToString.Trim)
Select notvalidmaterial_DT.Rows.Add({a("Material").ToString})
).ToList

Hope it helps!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.