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 8299559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:11:50+00:00 2026-06-08T16:11:50+00:00

I am building a WPF application that monitors a directory on the users computer.

  • 0

I am building a WPF application that monitors a directory on the users computer. The app uploads files from the monitored directory and then saves off some information into a SQLite db. Part of the business processing is to not re-process files that have already been uploaded and to re-upload files that have been uploaded but have changed since the last upload.

I have two helper methods that build and return a List<FileMetaData> that I used LINQ – Full Outer Join to join the. My problem is that the code doesn’t seem to work when I use my FileMetaData object. It seems like everything should all work but I’m at a loss as to why it’s not working. I would normally try to post as a comment on the other thread but I don’t currently have the “Rep” here to do that.

Below is a sample I’ve built that shows my problem if you run it in LINQpad. Make sure you set the language as “C# Program” before you click the run button. What should I do differently to have the sample work with the objects? Thanks a ton!

    void Main()
    {
        var dbItems = new List<FileMetaData>() { 
                new FileMetaData {FilePath = "C:\\Foo.txt", DbTimestamp = "1" },
                new FileMetaData {FilePath = "C:\\FooBar.txt", DbTimestamp = "3" },
            };

        var fsItems = new List<FileMetaData>() {
                new FileMetaData {FilePath = "C:\\Bar.txt", FsTimestamp = "2" },
                new FileMetaData {FilePath = "C:\\FooBar.txt", FsTimestamp = "3" },
            };

            var leftOuter = from d in dbItems
                    join f in fsItems on d.FilePath equals f.FilePath
                    into temp
                    from o in temp.DefaultIfEmpty(new FileMetaData(){})
                    select new FileMetaData { 
                        FilePath = d.FilePath, 
                        DbTimestamp = d.DbTimestamp,
                        FsTimestamp = o.FsTimestamp,
                    };

            var rightOuter = from f in fsItems
                    join d in dbItems on f.FilePath equals d.FilePath
                    into temp
                    from o in temp.DefaultIfEmpty(new FileMetaData(){})
                    select new FileMetaData { 
                        FilePath = f.FilePath, 
                        DbTimestamp = o.DbTimestamp,
                        FsTimestamp = f.FsTimestamp,
                    };

            var full = leftOuter.AsEnumerable().Union(rightOuter.AsEnumerable());

            leftOuter.Dump("Left Results");
            rightOuter.Dump("Right Results");

            full.Dump("Full Results");
    }

    // Define other methods and classes here
    public class FileMetaData
    {
        public string FilePath;
        public string DbTimestamp;
        public string FsTimestamp;
    }

EDIT:

The answer below was exactly what I was looking for. I implemented the IEqualityComparer as defined below and changed my call to var full = leftOuter.Union(rightOuter, new FileMetaDataCompare())…

    public class FileMetaDataCompare : IEqualityComparer<FileMetaData>
    {
        public bool Equals(FileMetaData x, FileMetaData y)
        {
            var areEqual = x.FilePath == y.FilePath;
            areEqual = areEqual && x.DbTimestamp == y.DbTimestamp;
            areEqual = areEqual && x.FsTimestamp == y.FsTimestamp;

            return areEqual;
        }

        public int GetHashCode(FileMetaData obj)
        {
            var hCode = string.Concat(obj.FilePath, obj.DbTimestamp, obj.FsTimestamp);
            return hCode.GetHashCode();
        }
    }
  • 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-08T16:11:52+00:00Added an answer on June 8, 2026 at 4:11 pm

    The problem is that Union will give you the results eliminating duplicates by checking for equality. When you use anonymous types, the definition of equality is ‘all fields have an equal value’. when you declare a type, it will use the Equals method. Since you have not overridden Equals, it defaults to ReferenceEquals, which means that two separate instances are not equal regardless of their field values.

    Three ways to solve this:

    1) Use anonymous types in your queries and convert to defined types after Union:

    var full = leftOuter.Union(rightOuter).Select(
        i=> new FileMetaData {
            FilePath = i.FilePath,
            DbTimestamp = i.DbTimestamp,
            FsTimestamp = i.FsTimestamp
        });
    

    2) Define an IEqualityComparer<FileMetaData> class that defines equality thay you want to (just FilePath? all fields?) and pass an instance of it to Union()

    3) Override Equals() (and GetHashCode()) in FileMetaData.

    2) and 3) will be very similar, but overriding Equals() can (and will) be used whenever you check for equality, not just in this situation.

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

Sidebar

Related Questions

I'm building a WPF application that will be run on laptop computers mounted in
I am building a WPF application that calls web services and displays the data
I'm building an application using WPF that will be a designer of sorts, meaning,
I am building a WPF application that takes in rows of data, and outputs
Building a stand alone WPF application that uses a MSSQL backend. I would like
I am building an application that has a WCF service that a WPF and
I am building a multiuser WPF application (requirement is a desktop app), database SQL
I'm building a WPF application that is designed to act as a notification toolbar
I'm building a WPF application, and I derived a bunch of controls from the
Im building a WPF 3.5 desktop app that has a self-hosted WCF service. The

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.