2

I am running into below mentioned error using the below LINQ query,what is the equivalent of not inSQL 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?)

Zein Makki
  • 29,485
  • 6
  • 52
  • 63
user3508811
  • 847
  • 4
  • 19
  • 43

1 Answers1

2

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)

Community
  • 1
  • 1
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
  • do you have any link or doc I can read to fix these issues by mysefl – user3508811 Mar 23 '17 at 06:57
  • @user3508811 https://blogs.msdn.microsoft.com/alexj/2009/03/25/tip-8-how-to-write-where-in-style-queries-using-linq-to-entities/ – Zein Makki Mar 23 '17 at 06:58
  • how can I check the generated queries and check the time?where can I find it? – user3508811 Mar 23 '17 at 06:58
  • @user3508811 check the updated answer, you can write the queries to the Visual Studio console. You can examine the time using the `Stopwatch` class, Google that one to find dozens of examples. – Zein Makki Mar 23 '17 at 07:01
  • I tried as `bitDB.log`,it throws an error `Error 1 'Dashboard.EntityFramework.BitDatabaseEntities' does not contain a definition for 'Log' and no extension method 'Log' accepting a first argument of type 'Dashboard.EntityFramework.BitDatabaseEntities' could be found (are you missing a using directive or an assembly reference?` – user3508811 Mar 23 '17 at 07:05
  • why is there a -1 to this answer,is there something wrong with this?please clarify – user3508811 Mar 23 '17 at 07:08
  • @user3508811 Well you said Linq-To-Sql in you question and not entity framework, that's why this is not working. Check the edited answer. – Zein Makki Mar 23 '17 at 07:29