Question

I have 3 databases that need to be compared for existing values on a where clause.A souce database that is like a huge directory, a middle database that holds all the entries that belong to the final database, which holds entries that are assigned to people by using and ID.

I started out to build a list of items that match in one database based on all the items in form the source and used linq contains on the final database (exclude the middle one because I am not sure how to handle this yet)

My code looks like this so far

public static List<Models.FinalEntry> CrossCheck(List<Data.Models.SourceDatabase>  sourceEntities, int finalEntryFilterID)
{ 
   var _tels = sourceEntities.Select(x => x.Phone).ToList();

   FinalEntryDataContext db = new FinalEntryDataContext ();

   var finalEntryMatches = db.FinalEntries.Where(x => !x.IsArchived &
      x.FinalEntryMemberID == finalEntryFilterID &
      _tels.Contains(x.Telephone))
    .ToList();

    return finalEntryMatches ;
}

The source lists may contain tens of thousands of entries and the final might contains a subset of the source entries. Now I cannot use an ID from source to final because the source database can be wiped out, changed or even become a different one. That is why I match by telephone now, but I want to extend that to address and name later - which will make performance even worse!

I have been reading that using a HashSet will increase comparing speed. I just never used a hashset before and not sure how to implement it to increase searching/matching performance here?

Is using a hashet a good way? Or is there another way this can be done?

Was it helpful?

Solution

This code isn't actually going to be doing a linear search through the list. It's not going to be doing any of the filtering in the application at all. This code is going to be translated into SQL and then performed at the database, which will be responsible for optimizing the query itself.

Were you to be doing this filtering within your application then yes, you'd want to use a HashSet that could be much more efficiently searched, but you aren't, so it's not relevant.

What you have is fine, so long as the query provider succeeds in translating the query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top