How to compare two tables in linq to sql? -


I am trying to compare two tables (i.e. value, count, etc.) in linq in sql, but I can not find the way to get it I tried the following,

  Table1.Any (i => i.itemNo == Table2.itemNo)   

gives this error Can you please help me?

Thanks in advance.

How about

  var is different = Table 1 Zip (Table 2, (J, K) => J.Titme no == KTMMO). Any (M => M);   

Edit

If Linq-to-Sql does not support ZIP.

  Var one = Table 1. Toolist (); Var two = table 2.ToList (); Var is different = one. Zip (Two, (J, K) => J.Etem No == KTMMO). Any (M => M);   

If the tables are bigger, then it can cause performance problems, in which case you will need a more sophisticated solution, if so, please ask.

EDIT2

If the tables are too large, you do not want to get all the data from the server and keep it in memory Additionaly, Linq and SQL Server rows Do not guarantee the order of the order unless you specify an order in the query. This is typically relayed for large results sets returned by a multi-processor server, where the effect of parallelism is likely to be played.

I suggest that Linq-to-Sql does not really cater well for your scenario, so you have to help in using something like this.

  string zipQuery = @ "from 1 to [table 1] [one] where it is not present (select * from [table 2] [two] where [two]. [No item ] = [One]. [Item] Union Select all 1 from [Table 2] [Two] where not present (Select * from [Table 1] [One] Where [One]. [Item No] = [Two ]. [Item no]) Union Select All 0 "Var is different = reference. AcquectaLize & lt; int & gt; (zipQuery). Single () == 1;   

This client will select on the server without returning too many data, but, It seems that you will agree that this is a lot more complicated.


EDIT3

OK, the zip approach to correct 1000 lines I have read your comments and I recommend that the code be changed accordingly. Table 1.ToList (Var) = Var 2 = Table 2.ToList (); Var Is different = a. Number! = Two. Number (a.zip (two, (o, t) => o.itemNo == k.itemNo). Any (M =>; M);

You may be able to list this way again by recipients Should consider orders.

  var one = Table1.OrderBy (o = & gt; o itemNo) .toList ();   

Strictly, the results of Linq-to-Sql return in any order unless an order is specified.

Comments