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

  • Home
  • SEARCH
  • 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 6192437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:56:33+00:00 2026-05-24T02:56:33+00:00

I have two Databases. They are both filled into DataTables using the GetTable1 \

  • 0

I have two Databases. They are both filled into DataTables using the GetTable1 \ GetTable2 functions.

What I am looking to do is to basically compare the datatables using LINQ.

I Have tried :

var infoQuery =
                    (from db1 in GetTable1().AsEnumerable()
                     select db1).Except                            
                            (from db2 in GetTable2().AsEnumerable()
                             select db2);

Also tried :
(Looks like it should be doing same as above ) :

var results = GetTable1().AsEnumerable().Except(GetTable2().AsEnumerable());

The results I get back are all the records in one table. I am looking for a return of 1 since 1 row is different between the two databases.

I am using default Equals method from Object , do I need to override that implementation to get this to work?

  • 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-05-24T02:56:34+00:00Added an answer on May 24, 2026 at 2:56 am

    It has to do with the way the rows are compared. Their values are not compared their references are.

    http://msdn.microsoft.com/en-us/library/bb300779.aspx

    To compare custom data types, implement the IEquatable generic interface and provide your own GetHashCode and Equals methods for the type. The default equality comparer, Default, is used to compare values of types that implement IEquatable.

    Example from MSDN:

    public class Product : IEquatable<Product>
    {
        public string Name { get; set; }
        public int Code { get; set; }
    
        public bool Equals(Product other)
        {
    
            //Check whether the compared object is null.
            if (Object.ReferenceEquals(other, null)) return false;
    
            //Check whether the compared object references the same data.
            if (Object.ReferenceEquals(this, other)) return true;
    
            //Check whether the products' properties are equal.
            return Code.Equals(other.Code) && Name.Equals(other.Name);
        }
    
        // If Equals() returns true for a pair of objects 
        // then GetHashCode() must return the same value for these objects.
    
        public override int GetHashCode()
        {
    
            //Get hash code for the Name field if it is not null.
            int hashProductName = Name == null ? 0 : Name.GetHashCode();
    
            //Get hash code for the Code field.
            int hashProductCode = Code.GetHashCode();
    
            //Calculate the hash code for the product.
            return hashProductName ^ hashProductCode;
        }
    }
    
    ...
    
        Product[] fruits1 = { new Product { Name = "apple", Code = 9 }, 
                               new Product { Name = "orange", Code = 4 },
                                new Product { Name = "lemon", Code = 12 } };
    
        Product[] fruits2 = { new Product { Name = "apple", Code = 9 } };
    
        //Get all the elements from the first array
        //except for the elements from the second array.
    
        IEnumerable<Product> except =
            fruits1.Except(fruits2);
    
        foreach (var product in except)
            Console.WriteLine(product.Name + " " + product.Code);
    
        /*
          This code produces the following output:
    
          orange 4
          lemon 12
        */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server 2000 and I have two databases that both replicate
I have two completely different MySQL databases and they both have their own user
I have two databases, one's MySql, one's MSSQL, I'm using php::pdo on both, except
I have a database with two tables ( Table1 and Table2 ). They both
I have transactional replication running between two databases. I fear they have fallen slightly
I have two databases at two different places, both databases are same with table
I have two databases: old and new. Both have a comments table. There are
Suppose I have two SQL Server 2008 databases, A and B. They initially were
I have two web forms which are filled in by the user. They contain
I have two local databases I'm trying to connect to using Java's Connection class.

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.