Reputation: 925
I am running into below mentioned error using the below LINQ query,what is the equivalent of not in
SQL to LINQ?I tried as where !cl.change_list_id.contains(from clcl in bitDB.component_labels_change_lists select clcl.change_list_id)
which isn't working?
var lookaheadRunChangeListIds = (from lrcl in bitDB.lookahead_run_change_list
join cl in bitDB.change_lists on lrcl.change_list_id equals cl.change_list_id
where lrcl.lookahead_run_id == lookaheadRunId
//and cl.change_list_id not in (select clcl.change_list_id from component_labels_change_lists as clcl)
where !cl.change_list_id.contains(from clcl in bitDB.component_labels_change_lists select clcl.change_list_id)
select cl.change_list.ToString()).ToList();
Error
Error 4 'int' does not contain a definition for 'contains' and no extension method 'contains' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
Upvotes: 2
Views: 2450
Reputation: 30042
The sequence contains the id and not the other way around, this is what the error is stating. You should swap these:
!(from clcl in bitDB.component_labels_change_lists
select clcl.change_list_id).Contains(cl.change_list_id)
You can also try:
!bitDB.component_labels_change_lists.Any(clcl => clcl.change_list_id == cl.change_list_id)
But Check the generated queries and choose whatever is faster (This might help on this one: https://stackoverflow.com/a/1412902/3185569)
Upvotes: 2