Tanveer
Tanveer

Reputation: 2097

Linq Statement between IList and datatable

I have a IList that i got after quering by linq to entities from one table. And by some other means i got a datatable as well that represent a table in database. Both tables have same columns. i want to search out those EmployeeIDs that are available in IList but not in datatable. Any please suggest how ican do that by using linq statement. I searched on net and found many clauses but still i am confused how to do that.

For example i found this code on post

from c in db.Customers
where !db.Products.Any(p => p.ProductID == c.ProductID)
select c;

Upvotes: 0

Views: 129

Answers (1)

Mathew Thompson
Mathew Thompson

Reputation: 56449

Assuming these:

DataTable dt; //your datatable

var results = from c in db.Customers
              where !db.Products.Any(p => p.ProductID == c.ProductID)
              select c;

You could then do:

var ids = results
    .Where(r => !dt.Rows.AsEnumerable
        .Any(d => d.ItemArray["EmployeeID"] == r.EmployeeID)
    .Select(r => r.EmployeeID);

Upvotes: 2

Related Questions