'How to exclude from query's result in linq?

First Query

Second Query

In the first picture I have the result of first query, the highlighted part indicates the rows that would be excluded by applying the filter on the second query, in the second I have the result of query select * from exlusion_table

I have to make a change to the first query to have it exclude the items retrieved from the second query

the first query:

var u = from a in cx.VW_LIST
        where (a.PRJ == codPrj) && (a.DATE > date_ || a.DATE == null || date_ == null)
        && (x.Contains(a.CODE) || x.Count() == 0)
        select a)

the second query:

var y = from esc in cx.EXCLUSION select esc

The first query should be modified to exclude all the rows that have the value fcode = the fcode of the second query (in the case in which the fscode of the second query = null) or that (fcode = fcode of the second query && fscode = fscode of the second query )



Solution 1:[1]

You can use Any(). ie:

var u = from a in cx.VW_LIST
        where (a.PRJ == codPrj) 
           && (a.DATE > date_ || a.DATE == null || date_ == null)
           && (x.Contains(a.CODE) || x.Count() == 0)
           && (!cx.EXCLUSION.Any( y => x.fscode == y.fscode && x.fcode == y.fcode ))
        select a)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cetin Basoz