Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

C# Linq - Not In

I have two data sets.  I want to link them together but select the data by filtering the data.

So, if

Data 1 contains A, B, C
and
Data 2 contains B, C, D

The result should return only A.

So, I did something like this.

var data = (from data1 in firstdata where data1.description == value select data1).ToList();

Now I'm trying to get the delta between the two.

var delta = (from data2 in seconddata where !data2.description.Contains (
                     from x in data select x.description
                    ) select data2).ToList();

I am getting an error on the second line.
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

Try using the "Except" keyword:

var data = new List<string> { "a", "b", "c" };
var data1 = new List<string> { "b", "c", "d" };

var delta = data.Except(data1);

Open in new window

Avatar of CipherIS

ASKER

Exception is not an option.
Why is "Except" not an option?

Please be more specific about the data types contained in firstdata and seconddata, as well as the desired output data type.
ASKER CERTIFIED SOLUTION
Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

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
I came up with something similar.

var exception = delta.Where(x = x> !data.Any(x2 => x2.Description == x.Description))

Let me know if you disagree.  

Thanks.