Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:41:54+00:00 2026-06-07T09:41:54+00:00

I am trying to compare two tables (i.e values, count, etc..) in linq to

  • 0

I am trying to compare two tables (i.e values, count, etc..) in linq to sql but I am not getting the way to achieve it. I tried the following,

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

It gives error. Could you please help me?

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:41:57+00:00Added an answer on June 7, 2026 at 9:41 am

    how about

    var isDifferent =
            Table1.Zip(Table2, (j, k) => j.itemNo == k.itemMo).Any(m => !m);
    

    EDIT

    if Linq-To-Sql does not support Zip.

    var one = Table1.ToList();
    var two = Table2.ToList();
    
    var isDifferent =
            one.Zip(two, (j, k) => j.itemNo == k.itemMo).Any(m => !m);
    

    if the tables are vary large this could cause performance problems. In that case you will need a much more sophisticated solution, if so, please ask.

    EDIT2

    If the tables are very large you don’t want to get all the data from the server and hold it memory. Additionaly, Linq and SQL server do not garauntee the order of the rows unless you specify an order in the query. This becomes espcially relavent for large result sets returned by a multi processor server where the effects of parallelism are likely to come into play.

    I suggest that Linq-to-Sql doesen’t really cater well for your scenario so you will have to help it out using ExecuteQuery somthing like this.

    string zipQuery =
    @"SELECT TOP 1
            1
        FROM
            [Table1] [one]
        WHERE
            NOT EXISTS (
               SELECT * FROM [Table2] [two] WHERE [two].[itemNo] = [one].[itemNo]
            )
    UNION ALL
    SELECT
            1
        FROM
            [Table2] [two]
        WHERE
            NOT EXISTS (
               SELECT * FROM [Table1] [one] WHERE [one].[itemNo] = [two].[itemNo]
            )
    UNION ALL
    SELECT 0";
    
    var isDifferent = context.ExecuteQuery<int>(zipQuery).Single() == 1; 
    

    This will do the select on the server without returning lots of data to the client but, I think you will agree is much more complicated.


    EDIT3

    Okay, the zip approach should be fine for 1000 rows. I’ve read your comment and I suggest changing the code accordingly.

    var one = Table1.ToList();
    var two = Table2.ToList();
    
    var isDifferent =
        one.Count != two.Count ||
        one.Zip(two, (o, t) => o.itemNo == k.itemNo).Any(m => !m);
    

    You should probably consider putting an order by on the list retrievers, like this.

    var one = Table1.OrderBy(o => o.itemNo).ToList();
    

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two tables, SQL Server, to verify some data. I
I'm trying to use an if statement to compare two arrays values.I am not
I'm trying to compare two different column types (not my doing, part of a
I am trying to compare two strings in Smalltalk, but I seem to be
I'm trying to compare two datetimes but I can't get it to work. public
I am trying to compare two tables to find rows in each table that
I'm trying to get a query to compare two tables by LEFT OUTER JOINing
Im trying to compare two different string encoded by sha512. But, result is different.
I am trying two compare two strings in JavaScript. But I guess there is
I am trying to compare two decimal values in Java script. I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.